1
votes

I'm trying to run a simple linear regression of in sklearn. I have a Pandas dataframe with two columns, "Likes" and "Attendance" Both columns have 18 samples.

lr = LinearRegression()
lr.fit(Likes,Attendance)

I get the following error:

C:\Anaconda3\lib\site-packages\sklearn\utils\validation.py:386: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and willraise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample. DeprecationWarning)

...

ValueError: Found arrays with inconsistent numbers of samples: [ 1 18]

Even after I reshaped the data using Likes.reshape(-1, 1), I got the same error.

Can anyone help?

1
I checked, and both Likes and Attendance have a shape of "(18,)"Andrew Smith

1 Answers

0
votes

You have a single feature in your data, therefore (as suggested in the error you posted) "Reshape your data ... using X.reshape(-1, 1)".

lr = LinearRegression()
lr.fit(X=Likes.reshape(-1, 1), y=Attendance)

I see that you tried this. Does my code above not work?