ValueError Found input variables with inconsistent numbers of samples 1 1000

+1 vote

I am trying to create one Machine Learning model using LinearRegression model, but I am getting the below error.

import pandas as pd
data = pd.read_csv('db.csv')
x = data['TV']
y = data['Sales']
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(x,y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/user/Python.framework/Versions/3.6/lib/python3.6/site-packages/sklearn/linear_model/base.py", line 512, in fit
    y_numeric=True, multi_output=True)
  File "/user/Python.framework/Versions/3.6/lib/python3.6/site-packages/sklearn/utils/validation.py", line 531, in check_X_y
    check_consistent_length(X, y)
  File "/user/Python.framework/Versions/3.6/lib/python3.6/site-packages/sklearn/utils/validation.py", line 181, in check_consistent_length
    " samples: %r" % [int(l) for l in lengths])
ValueError: Found input variables with inconsistent numbers of samples: [1, 1000]
Apr 14, 2020 in Machine Learning by akhtar
• 38,260 points
57,909 views

2 answers to this question.

+1 vote
Best answer

Hi@akhtar,

Here you used x as your feature parameter and y as your predictor. But your feature parameter should not be 1D. So check shape of x and if it is 1D, then convert it from 1D to 2D.

$ x.shape
$ x.reshape(-1,1)

Hope this will help you.

To learn more about AI ML, read the Artificial Intelligence tutorial to become proficient.

answered Apr 14, 2020 by MD
• 95,460 points

edited Aug 11, 2021 by Soumya
my x or feature variable is 2d but i also have same error .is there any other solution
Can you share your code along with error?
0 votes

Make sure your  data is 2 dimension and label is 1 dimension

Ready to dive into the world of machine learning? Supercharge your career and join our comprehensive Machine Learning Course today!

answered Nov 25, 2021 by Suria sarath

Related Questions In Machine Learning

0 votes
0 answers

ValueError: Found input variables with inconsistent numbers of samples: [11, 3988]

After reshaping also I am getting the ...READ MORE

Aug 27, 2020 in Machine Learning by sairam
• 160 points

edited Aug 27, 2020 by MD 5,306 views
0 votes
1 answer
0 votes
1 answer

Found input variables with inconsistent numbers of samples:

Hi@sagar, You have converted your Dataframe into an ...READ MORE

answered Jul 13, 2020 in Machine Learning by MD
• 95,460 points
5,300 views
0 votes
1 answer

problem with Found input variables with inconsistent numbers of samples: [1204, 134]

Hi@Alessandro, Here you used x as your feature parameter ...READ MORE

answered Jul 20, 2020 in Machine Learning by MD
• 95,460 points
5,144 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
0 votes
1 answer

ImportError: cannot import name 'LinearRegression' from 'sklearn'

Hi@akhtar, You got this error because LinearRegression is ...READ MORE

answered Apr 24, 2020 in Machine Learning by MD
• 95,460 points
24,806 views
0 votes
2 answers
0 votes
1 answer

ValueError: Found input variables with inconsistent numbers of samples: [616, 308]

Hi@Alshwarya, I think there is a problem with your ...READ MORE

answered Sep 23, 2020 in Machine Learning by MD
• 95,460 points
4,278 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP