check_cv#

sklearn.model_selection.check_cv(cv=5, y=None, *, classifier=False)[source]#

Input checker utility for building a cross-validator.

Parameters:
cvint, cross-validation generator, iterable or None, default=5

Determines the cross-validation splitting strategy. Possible inputs for cv are: - None, to use the default 5-fold cross validation, - integer, to specify the number of folds. - CV splitter, - An iterable that generates (train, test) splits as arrays of indices.

For integer/None inputs, if classifier is True and y is either binary or multiclass, StratifiedKFold is used. In all other cases, KFold is used.

Refer User Guide for the various cross-validation strategies that can be used here.

Changed in version 0.22: cv default value changed from 3-fold to 5-fold.

yarray-like, default=None

The target variable for supervised learning problems.

classifierbool, default=False

Whether the task is a classification task, in which case stratified KFold will be used.

Returns:
checked_cva cross-validator instance.

The return value is a cross-validator which generates the train/test splits via the split method.

Examples

>>> from sklearn.model_selection import check_cv
>>> check_cv(cv=5, y=None, classifier=False)
KFold(...)
>>> check_cv(cv=5, y=[1, 1, 0, 0, 0, 0], classifier=True)
StratifiedKFold(...)