我想使用支持向量机和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}$有人能帮我吗
首先,看一下SVC documentation和{a2}。在
SVC()
没有使用任何cv
参数,事实上,模型不考虑交叉验证。CV用于检查性能并防止过度装配。在交叉验证文档中使用的示例实际上是
SVC
。在在您的例子中,您可以使用cross_val_score,如下所示:
相关问题 更多 >
编程相关推荐