简体   繁体   English

ValueError:不能将折叠数n_folds = 3大于样本数:2

[英]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.

相关问题 ValueError:无法将拆分数n_splits = 3大于样本数:1 - ValueError: Cannot have number of splits n_splits=3 greater than the number of samples: 1 TypeError: __init__() 得到了一个意外的关键字参数“n_folds” - TypeError: __init__() got an unexpected keyword argument 'n_folds' 将数据集拆分为90,10而不是n_folds - Splitting dataset to 90,10 instead of n_folds ValueError:n_splits = 3不能大于每个类中的成员数 - ValueError: n_splits=3 cannot be greater than the number of members in each class ValueError:n_splits = 10不能大于每个类中的成员数 - ValueError: n_splits=10 cannot be greater than the number of members in each class Python ValueError: n_splits=3 不能大于每个 class 中的成员数 - Python ValueError: n_splits=3 cannot be greater than the number of members in each class 批量大小如何影响折叠中拆分的数据数量? - How does batch size affects number of data splitted in folds? ValueError: Number of labels is 1. 有效值为 2 to n_samples - 1 (inclusive) - ValueError: Number of labels is 1. Valid values are 2 to n_samples - 1 (inclusive) ValueError:所有输入数组 (x) 应具有相同数量的样本 - ValueError: All input arrays (x) should have the same number of samples 在列表中找到连续数字大于“ n”的最后一个数字 - find the last number in list with consecutive number of numbers greater than “n”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM