python 模型交叉验证法_python – 交叉验证和模型选择
我正在使用skilearn進行SVM培訓.我正在使用交叉驗證來評估估算器并避免過度擬合模型.
我將數據分成兩部分.訓練數據和測試數據.這是代碼:
import numpy as np
from sklearn import cross_validation
from sklearn import datasets
from sklearn import svm
X_train, X_test, y_train, y_test = cross_validation.train_test_split(
iris.data, iris.target, test_size=0.4, random_state=0
)
clf = svm.SVC(kernel='linear', C=1)
scores = cross_validation.cross_val_score(clf, X_train, y_train, cv=5)
print scores
# Now I need to evaluate the estimator *clf* on X_test.
clf.score(X_test,y_test)
# here, I get an error say that the model is not fitted using fit(), but normally,
# in cross_val_score function the model is fitted? What is the problem?
總結
以上是生活随笔為你收集整理的python 模型交叉验证法_python – 交叉验证和模型选择的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python将图片转动漫_如何把照片变成
- 下一篇: 航空频率表 2020_航空波段+调频、中