1

I recently posted here saying that I kept getting an error with my input, in which people told me to use numpy's reshape command. However I keep getting this error now from this code:

X_train= X_train.reshape(-1, 1)
X_test = X_test.reshape(-1, 1)
y_train = y.reshape(-1, 1)
myModel = LinearRegression() 

myModel.fit(X_train,y_train)

Error: 'Series' object has no attribute 'reshape' this comes up when running the first line.

3 Answers 3

3

Instead of using: X_train.reshape(-1,1)

Try using: X_train.values.reshape(-1,1)

Overall code:

X_train = X_train.values.reshape(-1, 1)
X_test = X_test.values.reshape(-1, 1)
y_train = y_train.values.reshape(-1, 1)
myModel = LinearRegression() 

myModel.fit(X_train, y_train)
Sign up to request clarification or add additional context in comments.

Comments

1

Try using

X_train= X_train.values.reshape(-1, 1)
X_test = X_test.values.reshape(-1, 1)
y_train = y.values.reshape(-1, 1)
myModel = LinearRegression() 

myModel.fit(X_train,y_train)

It will work

Comments

1
X_train = X_train.reshape(-1, 1)
X_test = X_test.reshape(-1, 1)

myModel = LinearRegression() 

myModel.fit(X_train, y_train)

1 Comment

Hi, this still comes up with the same error

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.