使用svc.fit()时出错:值错误:输入形状错误

2024-05-23 19:52:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我在数据框X中存储了关于帕金森病患者的数据,以及患者是否患有由y表示的帕金森病(0或1)。可通过以下方式检索:

X=pd.read_csv('parkinsons.data',index_col=0)
y=X['status']
X=X.drop(['status'],axis=1)

然后,我创建培训和测试样本:

X_train, y_train, X_test, y_test = train_test_split(X,y,test_size=0.3,random_state=7)

我想在此培训数据上使用SVC:

svc=SVC()
svc.fit(X_train,y_train)

然后,我得到一个错误: ValueError:错误的输入形状(59,22)。 我做错了什么?我怎样才能摆脱这个错误


Tags: csv数据test患者readdataindexstatus
2条回答

使用此

X_train, y_train, X_test, y_test =train_test_split(X,y,test_size=0.3,random_state=7)
svc=SVC()
svc.fit(X_train,X_test)

还是这个

X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3,random_state=7)
svc=SVC()
svc.fit(X_train,y_train)

我更喜欢用第二个

你对train_test_split的定义有问题,小心train_test_split首先输出X部分,然后输出Y部分。你实际上把y_列命名为X_测试。改变这一点,它应该可以工作:

X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3,random_state=7)

相关问题 更多 >