TypeError:\uu init_u9()获得意外的关键字参数“cv”

2024-06-11 09:11:43 发布

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

我想使用支持向量机和LeaveOneOut交叉验证(Loocv)。代码如下:

from sklearn.svm import SVC
from sklearn.model_selection import LeaveOneOut, train_test_split
import numpy as np
import pandas as pd

iRec = 'KSBPSSM_6_DCT_MIXED_49_937_937_1874_SMOTTMK.csv'
D = pd.read_csv(iRec, header=None)  # Using pandas

X = D.iloc[:, :-1].values
y = D.iloc[:, -1].values
from sklearn.utils import shuffle
X, y = shuffle(X, y)  # Avoiding bias
X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.75, 
test_size=0.25)

tpot = SVC(kernel='rbf', C=2.123, gamma=0.0039, cv=LeaveOneOut(), 
probability=True,)
tpot.fit(X_train, y_train)
print(tpot.score(X_test, y_test))
tpot.export('tpot_pipeline_'  + str(index) + '.py')

运行代码时,收到以下错误:

^{pr2}$

有人能帮我吗


Tags: csv代码fromtestimportpandasastrain
1条回答
网友
1楼 · 发布于 2024-06-11 09:11:43

首先,看一下SVC documentation和{a2}。在

SVC()没有使用任何cv参数,事实上,模型不考虑交叉验证。CV用于检查性能并防止过度装配。在

交叉验证文档中使用的示例实际上是SVC。在

在您的例子中,您可以使用cross_val_score,如下所示:

tpot = SVC(kernel='rbf', C=2.123, gamma=0.0039, probability=True)
scores = cross_val_score(tpot, X_test, y_test, cv=LeaveOneOut())
print(scores.mean())

相关问题 更多 >