Trying to make linear regression model fro machine learning, keep getting error
Question:
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.
Answers:
X_train= X_train.reshape(-1, 1)
X_test = X_test.reshape(-1, 1)
myModel = LinearRegression()
myModel.fit(X_train,y_train)
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)
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
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.
X_train= X_train.reshape(-1, 1)
X_test = X_test.reshape(-1, 1)
myModel = LinearRegression()
myModel.fit(X_train,y_train)
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)
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