1. Model Selection and Hyperparameter Tuning¶
Underfitting vs. Overfitting¶
| Condition | Training Error | Test Error | Cause |
|---|---|---|---|
| Underfitting | High | High | Model too simple |
| Overfitting | Low | High | Model too complex |
The goal is to choose a model with appropriate complexity that generalizes well to new data.
Hyperparameter Tuning¶
Hyperparameters control the learning process or model complexity (e.g., polynomial degree, tree depth, regularization , learning rate). They must be chosen before training.
Bad ideas:
Tuning on the entire dataset — no independent evaluation left.
Tuning on the test set — the test error is no longer an unbiased estimate.
Good idea: Split data into training, validation, and test sets.
Train on the training set.
Choose hyperparameters using the validation set.
Evaluate the final model on the test set (used only once).
2. Cross-Validation¶
Hold-out Validation¶
Split data into training / validation / test sets. The result may depend strongly on the particular split.
K-fold Cross-Validation¶
Split the training data into roughly equal folds.
For each trial : train on all folds except , validate on fold .
Average the validation performance over all trials.
Choose hyperparameters with the best average validation performance.
Practical considerations:
If is too small: training sets are small, performance estimate may be pessimistic.
If is too large: validation sets are tiny, estimate becomes more variable; computation is expensive.
Common choices: or .
In deep learning, a simple hold-out validation set is often used instead due to computational cost.
3. Evaluation Metrics for Regression¶
| Metric | Formula | Properties |
|---|---|---|
| MSE | Penalizes large errors more heavily | |
| MAE | $\frac{1}{n} \sum_{i=1}^{n} | y_i - \hat{y}_i |
4. Evaluation Metrics for Classification¶
Confusion Matrix¶
For binary classification (positive / negative):
| Predicted Positive | Predicted Negative | |
|---|---|---|
| Actual Positive | True Positive (TP) | False Negative (FN) |
| Actual Negative | False Positive (FP) | True Negative (TN) |
Type I error: False Positive (FP)
Type II error: False Negative (FN)
Basic Metrics¶
However, accuracy can be misleading for imbalanced classes.
Rate-based Metrics¶
For the positive class:
For the negative class:
Note: and .
Balanced accuracy:
Precision and Recall¶
Precision: Of all predicted positives, how many are correct?
Recall: Of all actual positives, how many are found?
Cost-Sensitive Evaluation¶
When different mistakes have different importance, assign weights :
5. ROC Curve and AUC¶
Operating Points and Thresholds¶
A classifier outputs scores; a decision threshold separates predicted positive from negative. By varying , we obtain different trade-offs between FPR and FNR. Each choice of is called an operating point.
DET Curve¶
Plot FNR (y-axis) vs. FPR (x-axis) for all thresholds. A better classifier has a DET curve closer to the bottom-left corner.
ROC Curve¶
Plot TPR = (y-axis) vs. FPR (x-axis) for all thresholds. A better classifier has an ROC curve closer to the top-left corner (high TPR, low FPR).
Equal Error Rate (EER): The point where .
AUC (Area Under the ROC Curve)¶
AUC provides an overall measure of classifier performance across all possible thresholds.
Scale-invariant: Changing the scale of prediction scores does not affect AUC.
Threshold-invariant: Summarizes performance over all thresholds.
Interpretation: AUC is the probability that a randomly chosen positive sample receives a higher score than a randomly chosen negative sample.
where and are scores of randomly drawn positive and negative samples.
Empirical AUC Formula¶
Given positive samples and negative samples with classifier scores . Define:
This is the fraction of positive-negative pairs that are correctly ranked by the classifier.
AUC ranges:
AUC = 1: perfect ranking
AUC = 0.5: random guessing
AUC = 0: completely reversed ranking