Ravi Ranjan
Ravi Ranjan

Reputation: 125

Found input variables with inconsistent numbers of samples: [159, 40]

I am new to ML. Trying out the Linear Regression and facing the below error. Please help me to resolve it. Here is my code:

  x=dataset.iloc[:,1:-1].values
y=dataset.iloc[:,-1].values
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
x_train,y_train,x_test,y_test=train_test_split(x,y,test_size=0.2)
regressor=LinearRegression()
regressor.fit(x_train,y_train)
y_pred=regressor.predict(x_test)

x.shape is [199,2] and y.shape is [199,]. after the execution of the code i getting the below error: ValueError: Found input variables with inconsistent numbers of samples: [159, 40]

Upvotes: 0

Views: 116

Answers (1)

filippo
filippo

Reputation: 5294

The order of the splits from train_test_split looks wrong. It should be:

x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)

Upvotes: 3

Related Questions