Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ValueError: shapes
#1
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
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020