Model Evaluation Metrics
Evaluating model performance requires task-specific metrics. Accuracy is misleading on imbalanced datasets: if a rare disease affects 1% of the population, a dummy classifier predicting “healthy” achieves 99% accuracy. Generalization error must be measured on independent data to evaluate utility.
Classification Metrics and Confusion Matrix
Binary classification performance is tabulated in a Confusion Matrix:
| Predicted Positive | Predicted Negative | |
|---|---|---|
| Actual Positive | True Positive (TP): 80 | False Negative (FN): 20 |
| Actual Negative | False Positive (FP): 10 | True Negative (TN): 90 |
In this disease-screening example with 200 samples:
- Precision: positive prediction accuracy. Out of 90 predicted positive cases, 80 were correct.
- Recall (Sensitivity): detection rate of actual positives. Out of 100 actual diseased patients, 80 were detected.
- F1 Score: harmonic mean of precision and recall, penalizing extreme values.
ROC Curve and AUC
The ROC curve plots True Positive Rate (Recall) against False Positive Rate () across decision thresholds. The Area Under the Curve (AUC) ranges from (random) to (perfect).
Regression Metrics
While classification relies on counting correct assignments, regression predicts continuous values. Typical metrics include Mean Squared Error (MSE), Root Mean Squared Error (RMSE), and Mean Absolute Error (MAE).
A normalized evaluation metric is the Coefficient of Determination (). The total variance in the data is captured by the Total Sum of Squares (SST). The variance explained by the model is the Sum of Squares due to Regression (SSR), and the unexplained variance is the Sum of Squared Errors (SSE).
The score represents the proportion of variance explained by the model:
Validation Methods
Proper validation is crucial for an iterative ML workflow to prevent overfitting and ensure model generalization.
- Train-test split: Uses a portion of data for training and a held-out test set purely for final evaluation.
- Train-val-test split: Introduces a validation set. The training set updates model parameters, the validation set is used for evaluation and hyperparameter tuning, and the test set is reserved exclusively for final evaluation.
- Stratification: When splitting non-representative training data (especially imbalanced classification datasets), stratification ensures the class distribution in all splits mirrors the original dataset.
Cross-Validation
- Cross-validation (CV): Splits the training data into folds. The model trains on folds and validates on the remaining one, rotating iteratively. This provides a more robust estimate of performance than a single validation set.
- Leave-one-out cross-validation (LOO CV): An extreme form of CV where equals the number of samples (). The model trains on samples and is validated on the single remaining point. While computationally expensive, it maximizes training data usage and provides unbiased performance estimates.
Example: Calculating Metrics
The following example demonstrates calculating classification metrics using a confusion matrix in scikit-learn:
Interactive Lab
Compute Precision, Recall, and F1 Score using scikit-learn metrics. Modify the ground truth labels or predictions to see how the scores change.
Exercise
Validate your knowledge of classification metric trade-offs: