[英]ValueError: Cannot have number of folds n_folds=3 greater than the number of samples: 2
I can't figure out why am I getting this error, because I explicitly set cv=2, so how n_fold could be equal to 3? 我不知道为什么会出现此错误,因为我显式设置了cv = 2,那么n_fold如何等于3? (I am using python 2 with 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)
After running the code I get: ValueError: Cannot have number of folds n_folds=3 greater than the number of samples: 2 运行代码后,我得到:ValueError:无法具有大于样本数的折叠数n_folds = 3:2
Ah, my usage of LogisticRegressionCV was completely incorrect. 啊,我对LogisticRegressionCV的使用是完全错误的。 Here is the valid one:
这是有效的:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.