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,240 points
54,107 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, then read the Artificial Intelligence tutorial. Also, enroll in Post Graduate Program in Artificial Intelligence and Machine Learning by NIT Warangal to become proficient.

answered Apr 14, 2020 by MD
• 95,440 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
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 4,406 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,440 points
4,599 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,440 points
4,009 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 3,510 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,440 points
18,103 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,440 points
3,293 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