|
255 | 255 | # train set and the test set. The difference is due to the small number of |
256 | 256 | # samples in the iris dataset. |
257 | 257 | # |
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. |
265 | 270 | # |
266 | 271 | # The interested reader can learn about other stratified cross-validation |
267 | 272 | # techniques in the [scikit-learn user |
|
0 commit comments