How to resolve raise ValueError(“bad input shape {0}”.format(shape)); ValueError: bad input shape (977, 57)

可紊 提交于 2020-08-10 19:52:08

问题


A dataset has more than 2500 rows and 22 columns including the age column. I have completed all of the processes for SVR. It going on. But I am still having to face an error. That is raise ValueError("bad input shape {0}".format(shape)), ValueError: bad input shape (977, 57). My input is SupportVectorRefModel.fit(X_train, y_train). How can I resolve this problem?

from sklearn.model_selection 
import train_test_split 
from sklearn.svm import SVR 

X_train, y_train = dataset.loc[:1000], dataset.loc[:1000] 
X_test, y_test = dataset.loc[1001], dataset.loc[1001] 
train_X, train_y = X_train.drop(columns=['age']), y_train.pop('age')
test_X, test_y = X_test.drop(columns=['age']), y_test.pop('age')

SupportVectorRefModel = SVR()
SupportVectorRefModel.fit(X_train, y_train)

Ouputs :

raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape (977, 57)

回答1:


You need to pass in train_X, train_y to your .fit function. You're currently passing in X_train which is the dataset before you remove the age column.

This is what it should be

SupportVectorRefModel = SVR()
SupportVectorRefModel.fit(train_x, train_y)


来源:https://stackoverflow.com/questions/61900518/how-to-resolve-raise-valueerrorbad-input-shape-0-formatshape-valueerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!