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 in Machine Learning by akhtar
• 10,540 points
1,580 views

1 answer to this question.

0 votes

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.

answered Apr 14 by MD
• 22,970 points

Related Questions In Machine Learning

0 votes
1 answer
0 votes
0 answers

Train-test split with 20% of data set aside - ML

I have an assignment of Making a ...READ MORE

May 24, 2019 in Machine Learning by Kim
91 views
+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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 947 views
0 votes
0 answers
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 in Machine Learning by MD
• 22,970 points
201 views
0 votes
1 answer
0 votes
1 answer

not able to see all columns and rows of a pandas DataFrame?

Hi@akhtar, Your data set contains lots of rows ...READ MORE

answered Apr 8 in Machine Learning by MD
• 22,970 points
75 views