我无法弄清楚为什么会出现此错误,因为我明确设置了cv = 2,那么n_fold如何等于3? (我正在使用带有anaconda的python 2)
import numpy as np
from sklearn.cross_validation import cross_val_score
from sklearn.linear_model import LogisticRegressionCV
classifier = LogisticRegressionCV(scoring='roc_auc')
x = np.array([[1, 2, 3], [3, 4, 9], [4, 9, 1], [8, 0, 4], [1, 1, 4], [1.1, 2, 4]])
y = np.array([True, False, True, False, True, False])
cross_val_score(classifier, x, y, cv=2)
运行代码后我得到:ValueError:折叠次数n_folds = 3大于样本数:2
答案 0 :(得分:0)
啊,我对LogisticRegressionCV的使用完全不正确。这是有效的:
import numpy as np
from sklearn.linear_model import LogisticRegressionCV
classifier = LogisticRegressionCV(scoring='roc_auc', cv=2)
classifier.store_cv_values = True
x = np.array([[1, 2, 3], [3, 4, 9], [4, 9, 1], [8, 0, 4], [1, 1, 4], [1.1, 2, 4]])
y = np.array([True, False, True, False, True, False])
classifier.fit(x, y)