Thanks to visit codestin.com
Credit goes to github.com

Skip to content

StratifiedKFold does not raise error when number of samples for all the classes is less than n_folds #6177

@raghavrv

Description

@raghavrv

We should raise an error instead of a warning (As pointed out by @MechCoder here)

import numpy as np
from sklearn.cross_validation import StratifiedKFold as OldSKF
from sklearn.model_selection import StratifiedKFold

X = np.array([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]])
y = np.array([3, 3, -1, -1, 2, 2])

for tr, te in OldSKF(y, n_folds=3):
    print tr, te
[1 3 5] [0 2 4]
[0 2 4] [1 3 5]
[0 1 2 3 4 5] []
for tr, te in StratifiedKFold(n_folds=6).split(X, y):
    print tr, te
[1 3 5] [0 2 4]
[0 2 4] [1 3 5]
[0 1 2 3 4 5] []
[0 1 2 3 4 5] []
[0 1 2 3 4 5] []
[0 1 2 3 4 5] []

To be tagged "Easy", "Need Contributor"

cc: @MechCoder @amueller @jnothman

Metadata

Metadata

Assignees

No one assigned

    Labels

    EasyWell-defined and straightforward way to resolve

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions