sklearn.cross_validation.check_cv

sklearn.cross_validation.check_cv(cv, X=None, y=None, classifier=False)[源代码]

Input checker utility for building a CV in a user friendly way.

Parameters:

cv : int, cross-validation generator or an iterable, optional

Determines the cross-validation splitting strategy. Possible inputs for cv are:

  • None, to use the default 3-fold cross-validation,
  • integer, to specify the number of folds.
  • An object to be used as a cross-validation generator.
  • An iterable yielding train/test splits.

For integer/None inputs, if y is binary or multiclass, StratifiedKFold used. If the estimator is a classifier or if y is neither binary nor multiclass, KFold is used.

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

X : array-like

The data the cross-val object will be applied on.

y : array-like

The target variable for a supervised learning problem.

classifier : boolean optional

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

Returns:

checked_cv: a cross-validation generator instance. :

The return value is guaranteed to be a cv generator instance, whatever the input type.