Skip to main content
Post Undeleted by Vishwas Sathish
Post Deleted by Vishwas Sathish

If you look at documentation of LinearRegression of scikit-learn, http://scikitLinearRegression of scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html.

fit(X, y, sample_weight=None)

X : numpy array or sparse matrix of shape [n_samples,n_features]

predict(X)

X : {array-like, sparse matrix}, shape = (n_samples, n_features)

As you can see XX has 2 dimensions, where as, your x_trainx_train and x_testx_test clearly have one. As suggested, add:

x_train = x_train.reshape(-1, 1)
x_test = x_test.reshape(-1, 1)

Before fitting and predicting the model. It should do the job.

If you look at documentation of LinearRegression of scikit-learn, http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html

fit(X, y, sample_weight=None)

X : numpy array or sparse matrix of shape [n_samples,n_features]

predict(X)

X : {array-like, sparse matrix}, shape = (n_samples, n_features)

As you can see X has 2 dimensions, where as, your x_train and x_test clearly have one. As suggested, add

x_train = x_train.reshape(-1, 1)
x_test = x_test.reshape(-1, 1)

Before fitting and predicting the model. It should do the job.

If you look at documentation of LinearRegression of scikit-learn.

fit(X, y, sample_weight=None)

X : numpy array or sparse matrix of shape [n_samples,n_features]

predict(X)

X : {array-like, sparse matrix}, shape = (n_samples, n_features)

As you can see X has 2 dimensions, where as, your x_train and x_test clearly have one. As suggested, add:

x_train = x_train.reshape(-1, 1)
x_test = x_test.reshape(-1, 1)

Before fitting and predicting the model.

Source Link

If you look at documentation of LinearRegression of scikit-learn, http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html

fit(X, y, sample_weight=None)

X : numpy array or sparse matrix of shape [n_samples,n_features]

predict(X)

X : {array-like, sparse matrix}, shape = (n_samples, n_features)

As you can see X has 2 dimensions, where as, your x_train and x_test clearly have one. As suggested, add

x_train = x_train.reshape(-1, 1)
x_test = x_test.reshape(-1, 1)

Before fitting and predicting the model. It should do the job.