Skip to content

Commit af56154

Browse files
committed
Merge pull request #5238 from rvraghav93/cvdoc
[MRG+1] DOC Make cv documentation consistent across our codebase
2 parents 4a6f96f + 882c346 commit af56154

File tree

10 files changed

+260
-103
lines changed

10 files changed

+260
-103
lines changed

sklearn/calibration.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,21 @@ class CalibratedClassifierCV(BaseEstimator, ClassifierMixin):
5353
with too few calibration samples (<<1000) since it tends to overfit.
5454
Use sigmoids (Platt's calibration) in this case.
5555
56-
cv : integer or cross-validation generator or "prefit", optional
57-
If an integer is passed, it is the number of folds (default 3).
58-
Specific cross-validation objects can be passed, see
59-
sklearn.cross_validation module for the list of possible objects.
56+
cv : integer/cross-validation generator/iterable or "prefit", optional
57+
Determines the cross-validation splitting strategy.
58+
Possible inputs for cv are:
59+
- None, to use the default 3-fold cross-validation,
60+
- integer, to specify the number of folds.
61+
- An object to be used as a cross-validation generator.
62+
- An iterable yielding train/test splits.
63+
64+
For integer/None inputs, if ``y`` is binary or multiclass,
65+
:class:`StratifiedKFold` used. If ``y`` is neither binary nor
66+
multiclass, :class:`KFold` is used.
67+
68+
Refer :ref:`User Guide <cross_validation>` for the various
69+
cross-validation strategies that can be used here.
70+
6071
If "prefit" is passed, it is assumed that base_estimator has been
6172
fitted already and all data is used for calibration.
6273

sklearn/covariance/graph_lasso_.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,18 @@ class GraphLassoCV(GraphLasso):
463463
The number of times the grid is refined. Not used if explicit
464464
values of alphas are passed.
465465
466-
cv : cross-validation generator, optional
467-
see sklearn.cross_validation module. If None is passed, defaults to
468-
a 3-fold strategy
466+
cv : int, cross-validation generator or an iterable, optional
467+
Determines the cross-validation splitting strategy.
468+
Possible inputs for cv are:
469+
- None, to use the default 3-fold cross-validation,
470+
- integer, to specify the number of folds.
471+
- An object to be used as a cross-validation generator.
472+
- An iterable yielding train/test splits.
473+
474+
For integer/None inputs :class:`KFold` is used.
475+
476+
Refer :ref:`User Guide <cross_validation>` for the various
477+
cross-validation strategies that can be used here.
469478
470479
tol: positive float, optional
471480
The tolerance to declare convergence: if the dual gap goes below

sklearn/cross_validation.py

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,15 +1202,20 @@ def cross_val_predict(estimator, X, y=None, cv=None, n_jobs=1,
12021202
The target variable to try to predict in the case of
12031203
supervised learning.
12041204
1205-
cv : integer or cross-validation generator, optional, default=3
1206-
A cross-validation generator to use. If int, determines the number
1207-
of folds in StratifiedKFold if estimator is a classifier and the
1208-
target y is binary or multiclass, or the number of folds in KFold
1209-
otherwise.
1210-
Specific cross-validation objects can be passed, see
1211-
sklearn.cross_validation module for the list of possible objects.
1212-
This generator must include all elements in the test set exactly once.
1213-
Otherwise, a ValueError is raised.
1205+
cv : int, cross-validation generator or an iterable, optional
1206+
Determines the cross-validation splitting strategy.
1207+
Possible inputs for cv are:
1208+
- None, to use the default 3-fold cross-validation,
1209+
- integer, to specify the number of folds.
1210+
- An object to be used as a cross-validation generator.
1211+
- An iterable yielding train/test splits.
1212+
1213+
For integer/None inputs, if ``y`` is binary or multiclass,
1214+
:class:`StratifiedKFold` used. If the estimator is a classifier
1215+
or if ``y`` is neither binary nor multiclass, :class:`KFold` is used.
1216+
1217+
Refer :ref:`User Guide <cross_validation>` for the various
1218+
cross-validation strategies that can be used here.
12141219
12151220
n_jobs : integer, optional
12161221
The number of CPUs to use to do the computation. -1 means
@@ -1371,13 +1376,20 @@ def cross_val_score(estimator, X, y=None, scoring=None, cv=None, n_jobs=1,
13711376
a scorer callable object / function with signature
13721377
``scorer(estimator, X, y)``.
13731378
1374-
cv : integer or cross-validation generator, optional, default=3
1375-
A cross-validation generator to use. If int, determines the number
1376-
of folds in StratifiedKFold if estimator is a classifier and the
1377-
target y is binary or multiclass, or the number of folds in KFold
1378-
otherwise.
1379-
Specific cross-validation objects can be passed, see
1380-
sklearn.cross_validation module for the list of possible objects.
1379+
cv : int, cross-validation generator or an iterable, optional
1380+
Determines the cross-validation splitting strategy.
1381+
Possible inputs for cv are:
1382+
- None, to use the default 3-fold cross-validation,
1383+
- integer, to specify the number of folds.
1384+
- An object to be used as a cross-validation generator.
1385+
- An iterable yielding train/test splits.
1386+
1387+
For integer/None inputs, if ``y`` is binary or multiclass,
1388+
:class:`StratifiedKFold` used. If the estimator is a classifier
1389+
or if ``y`` is neither binary nor multiclass, :class:`KFold` is used.
1390+
1391+
Refer :ref:`User Guide <cross_validation>` for the various
1392+
cross-validation strategies that can be used here.
13811393
13821394
n_jobs : integer, optional
13831395
The number of CPUs to use to do the computation. -1 means
@@ -1628,11 +1640,20 @@ def check_cv(cv, X=None, y=None, classifier=False):
16281640
16291641
Parameters
16301642
----------
1631-
cv : int, a cv generator instance, or None
1632-
The input specifying which cv generator to use. It can be an
1633-
integer, in which case it is the number of folds in a KFold,
1634-
None, in which case 3 fold is used, or another object, that
1635-
will then be used as a cv generator.
1643+
cv : int, cross-validation generator or an iterable, optional
1644+
Determines the cross-validation splitting strategy.
1645+
Possible inputs for cv are:
1646+
- None, to use the default 3-fold cross-validation,
1647+
- integer, to specify the number of folds.
1648+
- An object to be used as a cross-validation generator.
1649+
- An iterable yielding train/test splits.
1650+
1651+
For integer/None inputs, if ``y`` is binary or multiclass,
1652+
:class:`StratifiedKFold` used. If the estimator is a classifier
1653+
or if ``y`` is neither binary nor multiclass, :class:`KFold` is used.
1654+
1655+
Refer :ref:`User Guide <cross_validation>` for the various
1656+
cross-validation strategies that can be used here.
16361657
16371658
X : array-like
16381659
The data the cross-val object will be applied on.
@@ -1692,13 +1713,20 @@ def permutation_test_score(estimator, X, y, cv=None,
16921713
a scorer callable object / function with signature
16931714
``scorer(estimator, X, y)``.
16941715
1695-
cv : integer or cross-validation generator, optional, default=3
1696-
A cross-validation generator to use. If int, determines the number
1697-
of folds in StratifiedKFold if estimator is a classifier and the
1698-
target y is binary or multiclass, or the number of folds in KFold
1699-
otherwise.
1700-
Specific cross-validation objects can be passed, see
1701-
sklearn.cross_validation module for the list of possible objects.
1716+
cv : int, cross-validation generator or an iterable, optional
1717+
Determines the cross-validation splitting strategy.
1718+
Possible inputs for cv are:
1719+
- None, to use the default 3-fold cross-validation,
1720+
- integer, to specify the number of folds.
1721+
- An object to be used as a cross-validation generator.
1722+
- An iterable yielding train/test splits.
1723+
1724+
For integer/None inputs, if ``y`` is binary or multiclass,
1725+
:class:`StratifiedKFold` used. If the estimator is a classifier
1726+
or if ``y`` is neither binary nor multiclass, :class:`KFold` is used.
1727+
1728+
Refer :ref:`User Guide <cross_validation>` for the various
1729+
cross-validation strategies that can be used here.
17021730
17031731
n_permutations : integer, optional
17041732
Number of times to permute ``y``.

sklearn/feature_selection/rfe.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,20 @@ class RFECV(RFE, MetaEstimatorMixin):
290290
If within (0.0, 1.0), then `step` corresponds to the percentage
291291
(rounded down) of features to remove at each iteration.
292292
293-
cv : int or cross-validation generator, optional (default=None)
294-
If int, it is the number of folds.
295-
If None, 3-fold cross-validation is performed by default.
296-
Specific cross-validation objects can also be passed, see
297-
`sklearn.cross_validation module` for details.
293+
cv : int, cross-validation generator or an iterable, optional
294+
Determines the cross-validation splitting strategy.
295+
Possible inputs for cv are:
296+
- None, to use the default 3-fold cross-validation,
297+
- integer, to specify the number of folds.
298+
- An object to be used as a cross-validation generator.
299+
- An iterable yielding train/test splits.
300+
301+
For integer/None inputs, if ``y`` is binary or multiclass,
302+
:class:`StratifiedKFold` used. If the estimator is a classifier
303+
or if ``y`` is neither binary nor multiclass, :class:`KFold` is used.
304+
305+
Refer :ref:`User Guide <cross_validation>` for the various
306+
cross-validation strategies that can be used here.
298307
299308
scoring : string, callable or None, optional, default: None
300309
A string (see model evaluation documentation) or

sklearn/grid_search.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -656,13 +656,20 @@ class GridSearchCV(BaseSearchCV):
656656
the folds, and the loss minimized is the total loss per sample,
657657
and not the mean loss across the folds.
658658
659-
cv : integer or cross-validation generator, default=3
660-
A cross-validation generator to use. If int, determines
661-
the number of folds in StratifiedKFold if estimator is a classifier
662-
and the target y is binary or multiclass, or the number
663-
of folds in KFold otherwise.
664-
Specific cross-validation objects can be passed, see
665-
sklearn.cross_validation module for the list of possible objects.
659+
cv : int, cross-validation generator or an iterable, optional
660+
Determines the cross-validation splitting strategy.
661+
Possible inputs for cv are:
662+
- None, to use the default 3-fold cross-validation,
663+
- integer, to specify the number of folds.
664+
- An object to be used as a cross-validation generator.
665+
- An iterable yielding train/test splits.
666+
667+
For integer/None inputs, if ``y`` is binary or multiclass,
668+
:class:`StratifiedKFold` used. If the estimator is a classifier
669+
or if ``y`` is neither binary nor multiclass, :class:`KFold` is used.
670+
671+
Refer :ref:`User Guide <cross_validation>` for the various
672+
cross-validation strategies that can be used here.
666673
667674
refit : boolean, default=True
668675
Refit the best estimator with the entire dataset.
@@ -850,13 +857,20 @@ class RandomizedSearchCV(BaseSearchCV):
850857
the folds, and the loss minimized is the total loss per sample,
851858
and not the mean loss across the folds.
852859
853-
cv : integer or cross-validation generator, optional
854-
A cross-validation generator to use. If int, determines
855-
the number of folds in StratifiedKFold if estimator is a classifier
856-
and the target y is binary or multiclass, or the number
857-
of folds in KFold otherwise.
858-
Specific cross-validation objects can be passed, see
859-
sklearn.cross_validation module for the list of possible objects.
860+
cv : int, cross-validation generator or an iterable, optional
861+
Determines the cross-validation splitting strategy.
862+
Possible inputs for cv are:
863+
- None, to use the default 3-fold cross-validation,
864+
- integer, to specify the number of folds.
865+
- An object to be used as a cross-validation generator.
866+
- An iterable yielding train/test splits.
867+
868+
For integer/None inputs, if ``y`` is binary or multiclass,
869+
:class:`StratifiedKFold` used. If the estimator is a classifier
870+
or if ``y`` is neither binary nor multiclass, :class:`KFold` is used.
871+
872+
Refer :ref:`User Guide <cross_validation>` for the various
873+
cross-validation strategies that can be used here.
860874
861875
refit : boolean, default=True
862876
Refit the best estimator with the entire dataset.

sklearn/learning_curve.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,20 @@ def learning_curve(estimator, X, y, train_sizes=np.linspace(0.1, 1.0, 5),
5959
be big enough to contain at least one sample from each class.
6060
(default: np.linspace(0.1, 1.0, 5))
6161
62-
cv : integer or cross-validation generator, optional, default=3
63-
A cross-validation generator to use. If int, determines the number
64-
of folds in StratifiedKFold if estimator is a classifier and the
65-
target y is binary or multiclass, or the number of folds in KFold
66-
otherwise.
67-
Specific cross-validation objects can be passed, see
68-
sklearn.cross_validation module for the list of possible objects.
62+
cv : int, cross-validation generator or an iterable, optional
63+
Determines the cross-validation splitting strategy.
64+
Possible inputs for cv are:
65+
- None, to use the default 3-fold cross-validation,
66+
- integer, to specify the number of folds.
67+
- An object to be used as a cross-validation generator.
68+
- An iterable yielding train/test splits.
69+
70+
For integer/None inputs, if ``y`` is binary or multiclass,
71+
:class:`StratifiedKFold` used. If the estimator is a classifier
72+
or if ``y`` is neither binary nor multiclass, :class:`KFold` is used.
73+
74+
Refer :ref:`User Guide <cross_validation>` for the various
75+
cross-validation strategies that can be used here.
6976
7077
scoring : string, callable or None, optional, default: None
7178
A string (see model evaluation documentation) or
@@ -264,10 +271,20 @@ def validation_curve(estimator, X, y, param_name, param_range, cv=None,
264271
param_range : array-like, shape (n_values,)
265272
The values of the parameter that will be evaluated.
266273
267-
cv : integer, cross-validation generator, optional
268-
If an integer is passed, it is the number of folds (defaults to 3).
269-
Specific cross-validation objects can be passed, see
270-
sklearn.cross_validation module for the list of possible objects
274+
cv : int, cross-validation generator or an iterable, optional
275+
Determines the cross-validation splitting strategy.
276+
Possible inputs for cv are:
277+
- None, to use the default 3-fold cross-validation,
278+
- integer, to specify the number of folds.
279+
- An object to be used as a cross-validation generator.
280+
- An iterable yielding train/test splits.
281+
282+
For integer/None inputs, if ``y`` is binary or multiclass,
283+
:class:`StratifiedKFold` used. If the estimator is a classifier
284+
or if ``y`` is neither binary nor multiclass, :class:`KFold` is used.
285+
286+
Refer :ref:`User Guide <cross_validation>` for the various
287+
cross-validation strategies that can be used here.
271288
272289
scoring : string, callable or None, optional, default: None
273290
A string (see model evaluation documentation) or

sklearn/linear_model/coordinate_descent.py

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,11 +1221,18 @@ class LassoCV(LinearModelCV, RegressorMixin):
12211221
dual gap for optimality and continues until it is smaller
12221222
than ``tol``.
12231223
1224-
cv : integer or cross-validation generator, optional
1225-
If an integer is passed, it is the number of fold (default 3).
1226-
Specific cross-validation objects can be passed, see the
1227-
:mod:`sklearn.cross_validation` module for the list of possible
1228-
objects.
1224+
cv : int, cross-validation generator or an iterable, optional
1225+
Determines the cross-validation splitting strategy.
1226+
Possible inputs for cv are:
1227+
- None, to use the default 3-fold cross-validation,
1228+
- integer, to specify the number of folds.
1229+
- An object to be used as a cross-validation generator.
1230+
- An iterable yielding train/test splits.
1231+
1232+
For integer/None inputs, :class:`KFold` is used.
1233+
1234+
Refer :ref:`User Guide <cross_validation>` for the various
1235+
cross-validation strategies that can be used here.
12291236
12301237
verbose : bool or integer
12311238
Amount of verbosity.
@@ -1360,11 +1367,18 @@ class ElasticNetCV(LinearModelCV, RegressorMixin):
13601367
dual gap for optimality and continues until it is smaller
13611368
than ``tol``.
13621369
1363-
cv : integer or cross-validation generator, optional
1364-
If an integer is passed, it is the number of fold (default 3).
1365-
Specific cross-validation objects can be passed, see the
1366-
:mod:`sklearn.cross_validation` module for the list of possible
1367-
objects.
1370+
cv : int, cross-validation generator or an iterable, optional
1371+
Determines the cross-validation splitting strategy.
1372+
Possible inputs for cv are:
1373+
- None, to use the default 3-fold cross-validation,
1374+
- integer, to specify the number of folds.
1375+
- An object to be used as a cross-validation generator.
1376+
- An iterable yielding train/test splits.
1377+
1378+
For integer/None inputs, :class:`KFold` is used.
1379+
1380+
Refer :ref:`User Guide <cross_validation>` for the various
1381+
cross-validation strategies that can be used here.
13681382
13691383
verbose : bool or integer
13701384
Amount of verbosity.
@@ -1835,11 +1849,18 @@ class MultiTaskElasticNetCV(LinearModelCV, RegressorMixin):
18351849
dual gap for optimality and continues until it is smaller
18361850
than ``tol``.
18371851
1838-
cv : integer or cross-validation generator, optional
1839-
If an integer is passed, it is the number of fold (default 3).
1840-
Specific cross-validation objects can be passed, see the
1841-
:mod:`sklearn.cross_validation` module for the list of possible
1842-
objects.
1852+
cv : int, cross-validation generator or an iterable, optional
1853+
Determines the cross-validation splitting strategy.
1854+
Possible inputs for cv are:
1855+
- None, to use the default 3-fold cross-validation,
1856+
- integer, to specify the number of folds.
1857+
- An object to be used as a cross-validation generator.
1858+
- An iterable yielding train/test splits.
1859+
1860+
For integer/None inputs, :class:`KFold` is used.
1861+
1862+
Refer :ref:`User Guide <cross_validation>` for the various
1863+
cross-validation strategies that can be used here.
18431864
18441865
verbose : bool or integer
18451866
Amount of verbosity.
@@ -1985,11 +2006,18 @@ class MultiTaskLassoCV(LinearModelCV, RegressorMixin):
19852006
dual gap for optimality and continues until it is smaller
19862007
than ``tol``.
19872008
1988-
cv : integer or cross-validation generator, optional
1989-
If an integer is passed, it is the number of fold (default 3).
1990-
Specific cross-validation objects can be passed, see the
1991-
:mod:`sklearn.cross_validation` module for the list of possible
1992-
objects.
2009+
cv : int, cross-validation generator or an iterable, optional
2010+
Determines the cross-validation splitting strategy.
2011+
Possible inputs for cv are:
2012+
- None, to use the default 3-fold cross-validation,
2013+
- integer, to specify the number of folds.
2014+
- An object to be used as a cross-validation generator.
2015+
- An iterable yielding train/test splits.
2016+
2017+
For integer/None inputs, :class:`KFold` is used.
2018+
2019+
Refer :ref:`User Guide <cross_validation>` for the various
2020+
cross-validation strategies that can be used here.
19932021
19942022
verbose : bool or integer
19952023
Amount of verbosity.

0 commit comments

Comments
 (0)