- 留一法
from sklearn.model_selection import LeaveOneOut
loo = LeaveOneOut()
accuracy = 0;
for train, test in loo.split(X):
log_model.fit(X[train], y[train]) # fitting
y_p = log_model.predict(X[test])
if y_p == y[test] : accuracy += 1
print(accuracy / np.shape(X)[0]) - 交叉验证(10折)
- log_model = LogisticRegression(solver=‘liblinear’)
y_pred = cross_val_predict(log_model, X, y, cv=10)
print(metrics.accuracy_score(y, y_pred))
sklearn 留一法与交叉验证法
最新推荐文章于 2024-08-02 11:40:48 发布