I tried creating a simple linear regression model on just 30 rows of data. I got this error while trying to fit the model:
dataset = pd.read_csv('Salary_Data.csv')
x=dataset.iloc[:, :-1]
y=dataset.iloc[:, 1]
from sklearn.cross_validation import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 1/3, random_state = 0)
regressor = LinearRegression()
regressor.fit(x_train, y_test)
Here is the error message I got:
ValueError Traceback (most recent call last)
<ipython-input-53-8dc82dc6fe8b> in <module>()
----> 1 regressor.fit(x_train, y_test)
~\Anaconda3\lib\site-packages\sklearn\linear_model\base.py in fit(self, X, y, sample_weight)
480 n_jobs_ = self.n_jobs
481 X, y = check_X_y(X, y, accept_sparse=['csr', 'csc', 'coo'],
--> 482 y_numeric=True, multi_output=True)
483
484 if sample_weight is not None and np.atleast_1d(sample_weight).ndim > 1:
~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in check_X_y(X, y, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)
581 y = y.astype(np.float64)
582
--> 583 check_consistent_length(X, y)
584
585 return X, y
~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in check_consistent_length(*arrays)
202 if len(uniques) > 1:
203 raise ValueError("Found input variables with inconsistent numbers of"
--> 204 " samples: %r" % [int(l) for l in lengths])
205
206
ValueError: Found input variables with inconsistent numbers of samples: [20, 10]
print(x_train.shape)
andprint(y_train.shape)
$\endgroup$