Skip to content

Commit e0600a3

Browse files
MTN Add note on using stratification for cross validation (#878)
1 parent 0fcaed0 commit e0600a3

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

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

0 commit comments

Comments
 (0)