0

Please help me. After splitting my data into

X_train, y_train, X_test, y_test = train_test_split(X,y)

then passing it to my linear regression model I.e

linereg = LinearRegression().fit(X_train, y_train)

It brings out an error saying array must be 2D not 1D array. How can I make it a 2D array.

5
  • The error is happening because X needs to be a 2D array-like. Do you understand what that means? Commented Jun 17, 2019 at 1:04
  • This is tagged with Swift & Python, why? Commented Jun 17, 2019 at 9:14
  • You can just reshape X_train to be a 2D array-like. Commented Jun 17, 2019 at 9:37
  • No, please help me out Commented Jun 17, 2019 at 9:37
  • 1
    could you give us: X_train.shape and the orginal dataframe... Commented Jun 17, 2019 at 10:59

1 Answer 1

1

first split the data correctly

X_train, x_test, Y_train,y_test=train_test_split(features,labels,train_size=0.7, test_size=0.3, random_state=2)

try reshaping the x_train and x_test using reshape method.

x_test=x_test.reshape(-1,1)
x_train=x_train.reshape(-1,1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.