8000 DOC: Clarify `cv` parameter description in `GridSearchCV` (#12495) · thoo/scikit-learn@8d51696 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d51696

Browse files
QBatistathoo
authored andcommitted
DOC: Clarify cv parameter description in GridSearchCV (scikit-learn#12495)
#### Reference Issues/PRs <!-- Example: Fixes scikit-learn#1234. See also scikit-learn#3456. Please use keywords (e.g., Fixes) to create link to the issues or pull requests you resolved, so that they will automatically be closed when your pull request is merged. See https://github.com/blog/1506-closing-issues-via-pull-requests --> This PR addresses issue scikit-learn#12466. #### What does this implement/fix? Explain your changes. This PR does the 3 following things: - Rewrite the `cv` parameter description in `GridSearchCV` - Link the new `CV splitter` description to an existing example - Add an example with a custom iterable Thanks for reviewing this! Close scikit-learn#12466
1 parent fe8bd5c commit 8d51696

File tree

13 files changed

+67
-52
lines changed

13 files changed

+67
-52
lines changed

doc/modules/cross_validation.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,21 @@ validation iterator instead, for instance::
142142
>>> cross_val_score(clf, iris.data, iris.target, cv=cv) # doctest: +ELLIPSIS
143143
array([0.977..., 0.977..., 1. ..., 0.955..., 1. ])
144144

145+
Another option is to use an iterable yielding (train, test) splits as arrays of
146+
indices, for example::
147+
148+
>>> def custom_cv_2folds(X):
149+
... n = X.shape[0]
150+
... i = 1
151+
... while i <= 2:
152+
... idx = np.arange(n * (i - 1) / 2, n * i / 2, dtype=int)
153+
... yield idx, idx
154+
... i += 1
155+
...
156+
>>> custom_cv = custom_cv_2folds(iris.data)
157+
>>> cross_val_score(clf, iris.data, iris.target, cv=custom_cv)
158+
array([1. , 0.973...])
159+
145160
.. topic:: Data transformation with held out data
146161

147162
Just as it is important to test a predictor on data held-out from

examples/model_selection/plot_learning_curve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ def plot_learning_curve(estimator, title, X, y, ylim=None, cv=None,
5353
Possible inputs for cv are:
5454
- None, to use the default 3-fold cross-validation,
5555
- integer, to specify the number of folds.
56-
- An object to be used as a cross-validation generator.
57-
- An iterable yielding train/test splits.
56+
- :term:`CV splitter`,
57+
- An iterable yielding (train, test) splits as arrays of indices.
5858
5959
For integer/None inputs, if ``y`` is binary or multiclass,
6060
:class:`StratifiedKFold` used. If the estimator is not a classifier

sklearn/calibration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ class CalibratedClassifierCV(BaseEstimator, ClassifierMixin):
6363
6464
- None, to use the default 3-fold cross-validation,
6565
- integer, to specify the number of folds.
66-
- An object to be used as a cross-validation generator.
67-
- An iterable yielding train/test splits.
66+
- :term:`CV splitter`,
67+
- An iterable yielding (train, test) splits as arrays of indices.
6868
6969
For integer/None inputs, if ``y`` is binary or multiclass,
7070
:class:`sklearn.model_selection.StratifiedKFold` is used. If ``y`` is

sklearn/covariance/graph_lasso_.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ class GraphicalLassoCV(GraphicalLasso):
491491
492492
- None, to use the default 3-fold cross-validation,
493493
- integer, to specify the number of folds.
494-
- An object to be used as a cross-validation generator.
495-
- An iterable yielding train/test splits.
494+
- :term:`CV splitter`,
495+
- An iterable yielding (train, test) splits as arrays of indices.
496496
497497
For integer/None inputs :class:`KFold` is used.
498498
@@ -897,8 +897,8 @@ class GraphLassoCV(GraphicalLassoCV):
897897
898898
- None, to use the default 3-fold cross-validation,
899899
- integer, to specify the number of folds.
900-
- An object to be used as a cross-validation generator.
901-
- An iterable yielding train/test splits.
900+
- :term:`CV splitter`,
901+
- An iterable yielding (train, test) splits as arrays of indices.
902902
903903
For integer/None inputs :class:`KFold` is used.
904904

sklearn/feature_selection/rfe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ class RFECV(RFE, MetaEstimatorMixin):
356356
357357
- None, to use the default 3-fold cross-validation,
358358
- integer, to specify the number of folds.
359-
- An object to be used as a cross-validation generator.
360-
- An iterable yielding train/test splits.
359+
- :term:`CV splitter`,
360+
- An iterable yielding (train, test) splits as arrays of indices.
361361
362362
For integer/None inputs, if ``y`` is binary or multiclass,
363363
:class:`sklearn.model_selection.StratifiedKFold` is used. If the

sklearn/linear_model/coordinate_descent.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,8 +1308,8 @@ class LassoCV(LinearModelCV, RegressorMixin):
13081308
13091309
- None, to use the default 3-fold cross-validation,
13101310
- integer, to specify the number of folds.
1311-
- An object to be used as a cross-validation generator.
1312-
- An iterable yielding train/test splits.
1311+
- :term:`CV splitter`,
1312+
- An iterable yielding (train, test) splits as arrays of indices.
13131313
13141314
For integer/None inputs, :class:`KFold` is used.
13151315
@@ -1478,8 +1478,8 @@ class ElasticNetCV(LinearModelCV, RegressorMixin):
14781478
14791479
- None, to use the default 3-fold cross-validation,
14801480
- integer, to specify the number of folds.
1481-
- An object to be used as a cross-validation generator.
1482-
- An iterable yielding train/test splits.
1481+
- :term:`CV splitter`,
1482+
- An iterable yielding (train, test) splits as arrays of indices.
14831483
14841484
For integer/None inputs, :class:`KFold` is used.
14851485
@@ -2016,8 +2016,8 @@ class MultiTaskElasticNetCV(LinearModelCV, RegressorMixin):
20162016
20172017
- None, to use the default 3-fold cross-validation,
20182018
- integer, to specify the number of folds.
2019-
- An object to be used as a cross-validation generator.
2020-
- An iterable yielding train/test splits.
2019+
- :term:`CV splitter`,
2020+
- An iterable yielding (train, test) splits as arrays of indices.
20212021
20222022
For integer/None inputs, :class:`KFold` is used.
20232023
@@ -2195,8 +2195,8 @@ class MultiTaskLassoCV(LinearModelCV, RegressorMixin):
21952195
21962196
- None, to use the default 3-fold cross-validation,
21972197
- integer, to specify the number of folds.
2198-
- An object to be used as a cross-validation generator.
2199-
- An iterable yielding train/test splits.
2198+
- :term:`CV splitter`,
2199+
- An iterable yielding (train, test) splits as arrays of indices.
22002200
22012201
For integer/None inputs, :class:`KFold` is used.
22022202

sklearn/linear_model/least_angle.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,8 @@ class LarsCV(Lars):
10071007
10081008
- None, to use the default 3-fold cross-validation,
10091009
- integer, to specify the number of folds.
1010-
- An object to be used as a cross-validation generator.
1011-
- An iterable yielding train/test splits.
1010+
- :term:`CV splitter`,
1011+
- An iterable yielding (train, test) splits as arrays of indices.
10121012
10131013
For integer/None inputs, :class:`KFold` is used.
10141014
@@ -1230,8 +1230,8 @@ class LassoLarsCV(LarsCV):
12301230
12311231
- None, to use the default 3-fold cross-validation,
12321232
- integer, to specify the number of folds.
1233-
- An object to be used as a cross-validation generator.
1234-
- An iterable yielding train/test splits.
1233+
- :term:`CV splitter`,
1234+
- An iterable yielding (train, test) splits as arrays of indices.
12351235
12361236
For integer/None inputs, :class:`KFold` is used.
12371237

sklearn/linear_model/omp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,8 @@ class OrthogonalMatchingPursuitCV(LinearModel, RegressorMixin):
790790
791791
- None, to use the default 3-fold cross-validation,
792792
- integer, to specify the number of folds.
793-
- An object to be used as a cross-validation generator.
794-
- An iterable yielding train/test splits.
793+
- :term:`CV splitter`,
794+
- An iterable yielding (train, test) splits as arrays of indices.
795795
796796
For integer/None inputs, :class:`KFold` is used.
797797

sklearn/linear_model/ridge.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,8 +1211,8 @@ class RidgeCV(_BaseRidgeCV, RegressorMixin):
12111211
12121212
- None, to use the efficient Leave-One-Out cross-validation
12131213
- integer, to specify the number of folds.
1214-
- An object to be used as a cross-validation generator.
1215-
- An iterable yielding train/test splits.
1214+
- :term:`CV splitter`,
1215+
- An iterable yielding (train, test) splits as arrays of indices.
12161216
12171217
For integer/None inputs, if ``y`` is binary or multiclass,
12181218
:class:`sklearn.model_selection.StratifiedKFold` is used, else,
@@ -1323,8 +1323,8 @@ class RidgeClassifierCV(LinearClassifierMixin, _BaseRidgeCV):
13231323
13241324
- None, to use the efficient Leave-One-Out cross-validation
13251325
- integer, to specify the number of folds.
1326-
- An object to be used as a cross-validation generator.
1327-
- An iterable yielding train/test splits.
1326+
- :term:`CV splitter`,
1327+
- An iterable yielding (train, test) splits as arrays of indices.
13281328
13291329
Refer :ref:`User Guide <cross_validation>` for the various
13301330
cross-validation strategies that can be used here.

sklearn/model_selection/_search.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -901,8 +901,8 @@ class GridSearchCV(BaseSearchCV):
901901
902902
- None, to use the default 3-fold cross validation,
903903
- integer, to specify the number of folds in a `(Stratified)KFold`,
904-
- An object to be used as a cross-validation generator.
905-
- An iterable yielding train, test splits.
904+
- :term:`CV splitter`,
905+
- An iterable yielding (train, test) splits as arrays of indices.
906906
907907
For integer/None inputs, if the estimator is a classifier and ``y`` is
908908
either binary or multiclass, :class:`StratifiedKFold` is used. In all
@@ -1235,8 +1235,8 @@ class RandomizedSearchCV(BaseSearchCV):
12351235
12361236
- None, to use the default 3-fold cross validation,
12371237
- integer, to specify the number of folds in a `(Stratified)KFold`,
1238-
- An object to be used as a cross-validation generator.
1239-
- An iterable yielding train, test splits.
1238+
- :term:`CV splitter`,
1239+
- An iterable yielding (train, test) splits as arrays of indices.
12401240
12411241
For integer/None inputs, if the estimator is a classifier and ``y`` is
12421242
either binary or multiclass, :class:`StratifiedKFold` is used. In all

0 commit comments

Comments
 (0)
0