You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: python_scripts/cross_validation_stratification.html
+11-7Lines changed: 11 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1158,13 +1158,17 @@ <h1>Stratification<a class="headerlink" href="#stratification" title="Link to th
1158
1158
<p>In this case, we observe that the class counts are very close both in the
1159
1159
train set and the test set. The difference is due to the small number of
1160
1160
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 <aclass="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>
1168
1172
<p>The interested reader can learn about other stratified cross-validation
1169
1173
techniques in the <aclass="reference external" href="https://scikit-learn.org/stable/modules/cross_validation.html#cross-validation-iterators-with-stratification-based-on-class-labels">scikit-learn user
0 commit comments