Model Pipeline - Stratified K-fold
Stratified K-fold splits data into K parts while keeping the class proportions the same in each part. This helps train and test models fairly on imbalanced data.
Stratified K-fold splits data into K parts while keeping the class proportions the same in each part. This helps train and test models fairly on imbalanced data.
Loss 0.65 |***** 0.50 |**** 0.40 |*** 0.35 |** 0.30 |*
| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 0.65 | 0.60 | Model starts learning, loss high, accuracy low |
| 2 | 0.50 | 0.72 | Loss decreases, accuracy improves |
| 3 | 0.40 | 0.80 | Model learns important patterns |
| 4 | 0.35 | 0.85 | Loss continues to drop, accuracy rises |
| 5 | 0.30 | 0.88 | Training converges with good accuracy |
Stratified K-fold in machine learning?from sklearn.model_selection import StratifiedKFold
import numpy as np
X = np.arange(10)
y = np.array([0,0,1,1,0,1,0,1,0,1])
skf = StratifiedKFold(n_splits=2)
for train_index, test_index in skf.split(X, y):
print(len(train_index), len(test_index))from sklearn.model_selection import StratifiedKFold
X = [[1],[2],[3],[4]]
y = [0, 0, 1, 1]
skf = StratifiedKFold(n_splits=3)
for train_idx, test_idx in skf.split(X, y):
print(train_idx, test_idx)Pass the test and this pattern moves unknown