簡體   English   中英

ValueError:不能將折疊數n_folds = 3大於樣本數:2

[英]ValueError: Cannot have number of folds n_folds=3 greater than the number of samples: 2

我不知道為什么會出現此錯誤,因為我顯式設置了cv = 2,那么n_fold如何等於3? (我在蟒蛇上使用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

啊,我對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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM