问题描述
一个数据集具有多个2500 rows
和22 columns
(包括年龄列).我已经完成了SVR的所有过程.它继续.但是我仍然要面对一个错误.那是raise ValueError("bad input shape {0}".format(shape)), ValueError: bad input shape (977, 57)
.我的输入是SupportVectorRefModel.fit(X_train, y_train)
.我该如何解决这个问题?
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)
食物:
raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape (977, 57)
推荐答案
您需要将train_X, train_y
传递给您的.fit
函数.您当前正在传入X_train
,它是删除age
列之前 的数据集.
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.
这应该是
SupportVectorRefModel = SVR()
SupportVectorRefModel.fit(train_x, train_y)
这篇关于如何解决引发ValueError(“错误的输入形状{0}".format(shape)); ValueError:输入形状错误(977,57)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!