0
$\begingroup$

On doing this-

x = np.random.rand(200)
.
.

from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x,y, test_size =0.20, random_state = 0)
    reg = LinearRegression()
    reg.fit(x_train,y_train)

I got the following error
enter image description here


Although I do understand that I am not passing the parameters properly. But not
sure how to make it into a 2D array for linear regression
$\endgroup$
0
$\begingroup$

By using np.reshape you can transform your input x to Scikit's necessary input shape

from sklearn.model_selection import train_test_split

x_train, x_test, y_train, y_test = train_test_split(x,y, test_size =0.20, random_state = 0)
x_train = x_train.reshape(-1,1)
x_test = x_test.reshape(-1,1)
reg = LinearRegression()
reg.fit(x_train,y_train)
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.