scikit-learn/scikit-learn — Issue #663: Bug in error message in StratifiedKFold initialization
Author: conradlee
Created: 2012-03-01 10:45:41+00:00
State: open

In the initialization method of StratifiedKFold (in cross_validation.py), there is some code that makes sure that `k` is smaller than the number of entries in the least-populated class. I guess the idea is that each fold should contain at least one example from every class.

In the case that the least populated class has fewer entires than k, the error message says `"Cannot have number of folds k=%d smaller than %d, the minimum number of labels for any class." % (k, min_labels)`

I think it should say "Cannot have number of folds k=%d **greater** than %d, the minimum number of labels for any class." Here's a snippet of the error message in context

```python
def __init__(self, y, k, indices=True):
y = np.asarray(y)
n = y.shape[0]
_validate_kfold(k, n)
_, y_sorted = unique(y, return_inverse=True)
min_labels = np.min(np.bincount(y_sorted))
if k > min_labels:
raise ValueError("Cannot have number of folds k=%d"
" smaller than %d, the minimum"
" number of labels for any class."
% (k, min_labels))
```