пожалуйста, обратитесь к блокноту по следующему адресу
эта часть кода,
scores = cross_val_score(LogisticRegression(), X, y, scoring='accuracy', cv=10)
print scores
print scores.mean()
генерирует следующую ошибку на 64-битной машине Windows 7
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-37-4a10affe67c7> in <module>()
1 # evaluate the model using 10-fold cross-validation
----> 2 scores = cross_val_score(LogisticRegression(), X, y, scoring='accuracy', cv=10)
3 print scores
4 print scores.mean()
C:\Python27\lib\site-packages\sklearn\cross_validation.pyc in cross_val_score(estimator, X, y, scoring, cv, n_jobs, verbose, fit_params, score_func, pre_dispatch)
1140 allow_nans=True, allow_nd=True)
1141
-> 1142 cv = _check_cv(cv, X, y, classifier=is_classifier(estimator))
1143 scorer = check_scoring(estimator, score_func=score_func, scoring=scoring)
1144 # We clone the estimator to make sure that all the folds are
C:\Python27\lib\site-packages\sklearn\cross_validation.pyc in _check_cv(cv, X, y, classifier, warn_mask)
1366 if classifier:
1367 if type_of_target(y) in ['binary', 'multiclass']:
-> 1368 cv = StratifiedKFold(y, cv, indices=needs_indices)
1369 else:
1370 cv = KFold(_num_samples(y), cv, indices=needs_indices)
C:\Python27\lib\site-packages\sklearn\cross_validation.pyc in __init__(self, y, n_folds, indices, shuffle, random_state)
428 for test_fold_idx, per_label_splits in enumerate(zip(*per_label_cvs)):
429 for label, (_, test_split) in zip(unique_labels, per_label_splits):
--> 430 label_test_folds = test_folds[y == label]
431 # the test split can be too big because we used
432 # KFold(max(c, self.n_folds), self.n_folds) instead of
IndexError: too many indices for array
Я использую scikit.learn 0.15.2, предлагается здесь, что может Проблема для Windows 7, 64-битная машина.
==============обновление===============
Я обнаружил, что следующий код действительно работает
from sklearn.cross_validation import KFold
cv = KFold(X.shape[0], 10, shuffle=True, random_state=33)
scores = cross_val_score(LogisticRegression(), X, y, scoring='accuracy', cv=cv)
print scores
==============обновление 2==============
кажется, из-за какого-то обновления пакета я больше не могу воспроизводить такую ошибку на своей машине. Если вы столкнулись с той же проблемой на 64-битной машине с Windows 7, сообщите мне об этом.
y
? - person Fred Foo   schedule 22.10.2014cv
?X.shape[0] == 6366
тоже? - person eickenberg   schedule 22.10.2014cv=10
попытается составить стратифицированное 10-кратное резюме,KFold
нет. - person Fred Foo   schedule 22.10.2014cv=StratifiedKFold(y, 10)
было бы моим следующим шагом диагностики, если бы все остальное было равным. - person eickenberg   schedule 22.10.2014cv=StratifiedKFold(y, 10)
на самом деле работает нормально. - person tesla1060   schedule 23.10.2014StratifiedKFold
по умолчанию. Единственный параметр, который может отличаться, это, возможно,indices=False
. Что произойдет, если вы установитеcv=StratifiedKFold(y, 10, indices=False)
? (Хотя я не уверен, почему это было бы установлено именно так) - person eickenberg   schedule 23.10.2014