AttributeError: 'Series' object has no attribute 'reshape' - When You Want to Concatenate Two Columns for Looking at LR Model Performance (Error)

y_test is not an ndarray. It's a panda.core.series.Series object.

What did that for me?

It's coming out of train_test_split (sklearn.model_selection) which has been given a y that is a Series object and it politely returned the same.

What happened? When you created your y from the input data, did you leave out the .values? I did - because I left it out intentionally when creating the X - so that I could use a cute snippet to automatically (without visual inspection - you know me, I'm Mr. Automation) find the non-numeric columns to subject to one-hot encoding.

And, typing stuff manually (a good reason to use a template and make edits) - I did the same with the y creation.

If you have y = dataset[:,-1].values, you get an ndarray and all is well.

Be warned :)

Why do we care? Because, to concatenate two vectors as two columns side by side, you need to use reshape:

cmp_matrix = np.concatenate( (y_pred.reshape(len(y_pred),1), y_test.reshape((len(y_test),1)) ), axis=1 )

Comments

Popular posts from this blog

The Dummy Variable Trap

Your Handy ML Reference

Efficient Learning Machines: Theories, Concepts, and Applications for Engineers and System Designers