Skip to content

Commit 821d34b

Browse files
committed
[ci skip] MTN Add note on using stratification for cross validation (#878) e0600a3
1 parent 18d5f1f commit 821d34b

3 files changed

Lines changed: 24 additions & 15 deletions

File tree

_sources/python_scripts/cross_validation_stratification.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,18 @@
255255
# train set and the test set. The difference is due to the small number of
256256
# samples in the iris dataset.
257257
#
258-
# In other words, stratifying is more effective than just shuffling when it
259-
# comes to making sure that the distributions of classes in all the folds are
260-
# representative of the entire dataset. As training and testing folds have
261-
# similar class distributions, stratifying leads to a more realistic measure of
262-
# the model’s ability to generalize. This is specially important when the
263-
# performance metrics depend on the proportion of the positive class, as we will
264-
# see in a future notebook.
258+
# Stratification is especially useful for ensuring that rare classes are
259+
# represented in every cross validation split. In particular, if a class is
260+
# absent from one or more splits, some classification metrics may become
261+
# undefined. It is also the case that some performance metrics depend on
262+
# the proportion of the positive class, as we will see in a future notebook.
263+
#
264+
# However, as noted in the [scikit-learn user
265+
# guide](https://scikit-learn.org/stable/modules/cross_validation.html#cross-validation-iterators-with-stratification-based-on-class-labels),
266+
# stratification makes the folds more homogeneous. In the presence of severe
267+
# class imbalance, this can artificially reduce the variability of performance
268+
# metrics across folds, causing the observed variability to underestimate the
269+
# true uncertainty in model performance.
265270
#
266271
# The interested reader can learn about other stratified cross-validation
267272
# techniques in the [scikit-learn user

python_scripts/cross_validation_stratification.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,13 +1158,17 @@ <h1>Stratification<a class="headerlink" href="#stratification" title="Link to th
11581158
<p>In this case, we observe that the class counts are very close both in the
11591159
train set and the test set. The difference is due to the small number of
11601160
samples in the iris dataset.</p>
1161-
<p>In other words, stratifying is more effective than just shuffling when it
1162-
comes to making sure that the distributions of classes in all the folds are
1163-
representative of the entire dataset. As training and testing folds have
1164-
similar class distributions, stratifying leads to a more realistic measure of
1165-
the model’s ability to generalize. This is specially important when the
1166-
performance metrics depend on the proportion of the positive class, as we will
1167-
see in a future notebook.</p>
1161+
<p>Stratification is especially useful for ensuring that rare classes are
1162+
represented in every cross validation split. In particular, if a class is
1163+
absent from one or more splits, some classification metrics may become
1164+
undefined. It is also the case that some performance metrics depend on
1165+
the proportion of the positive class, as we will see in a future notebook.</p>
1166+
<p>However, as noted in the <a class="reference external" href="https://scikit-learn.org/stable/modules/cross_validation.html#cross-validation-iterators-with-stratification-based-on-class-labels">scikit-learn user
1167+
guide</a>,
1168+
stratification makes the folds more homogeneous. In the presence of severe
1169+
class imbalance, this can artificially reduce the variability of performance
1170+
metrics across folds, causing the observed variability to underestimate the
1171+
true uncertainty in model performance.</p>
11681172
<p>The interested reader can learn about other stratified cross-validation
11691173
techniques in the <a class="reference external" href="https://scikit-learn.org/stable/modules/cross_validation.html#cross-validation-iterators-with-stratification-based-on-class-labels">scikit-learn user
11701174
guide</a>.</p>

searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)