Home > Mobile >  Trying to make linear regression model fro machine learning, keep getting error
Trying to make linear regression model fro machine learning, keep getting error

Time:10-11

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.

CodePudding user response:

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)

CodePudding user response:

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

CodePudding user response:

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

myModel = LinearRegression() 

myModel.fit(X_train, y_train)
  • Related