Python Forum

Full Version: ValueError: shapes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

I am having a very strange problem with predicting using sklearn.
Currently doing the IBM course “Data analysis with Python”. This is the data:

path = 'https://ibm.box.com/shared/static/q6iiqb1pd7wo8r3q28jvgsrprzezjqk3.csv'

At some it asks to make a dataframe of a four columns:
Z = df[['horsepower', 'curb-weight', 'engine-size', 'highway-mpg']]

After fitting the data, with lm.fit() function, we use the predict function:

lm.predict(Z)
It gives the following error message:

"ValueError: shapes (201,4) and (2,1) not aligned: 4 (dim 1) != 2 (dim 0)"

This is strange as I checked all the columns in the dataframe with the len() function and all are 201.
The first question would be why is it giving this error message. The second question is, how to solve this.

Many thanks for your help.

N