Sub topic 1
Why Every Project Starts with a Baseline
Prerequisites
Assume you know features, labels, training, prediction, and common metrics such as accuracy, recall, and mean absolute error. You should also be comfortable with basic Python and scikit-learn.
Why Every Project Starts with a Baseline
A baseline is a simple reference method used for comparison. It answers a practical question: does the proposed model perform better than a method that requires little or no learning?
Without a baseline, a score has no context. A model with 90% accuracy may be useful, or it may merely predict the most common class. A baseline also exposes unnecessary complexity. If a sophisticated model barely beats a simple one, its extra cost may not be justified.
Picking a Metric That Reflects the Goal
Choose the metric before interpreting model scores. The metric should reflect both the task and the cost of errors.
| Task condition | Useful metric |
|---|---|
| Classes are balanced and errors have similar costs | Accuracy |
| Positive cases are rare | Precision, recall, or balanced accuracy |
| Numeric errors have business meaning | MAE or RMSE |
For imbalanced classification, accuracy can be misleading. A classifier that always predicts the majority class may achieve 95% accuracy while detecting none of the rare cases. Balanced accuracy gives equal weight to each class.
Splitting Data and Avoiding Leakage
Use the same data protocol for the baseline and candidate. A typical protocol has training data for fitting, validation data for choices, and a final test set for one unbiased estimate.
Data leakage occurs when information unavailable at prediction time enters training or evaluation. Examples include scaling all data before splitting, using future values in a forecast, or allowing duplicate users across train and test sets.
For classification, preserve class proportions with a stratified split. For time series, split chronologically rather than randomly.
Trivial Baselines: The Floor to Beat
Start with a predictor that ignores most features:
- Classification: always predict the majority class.
- Regression: always predict the training mean or median.
- Forecasting: predict that the next value equals the latest observed value.
from sklearn.dummy import DummyClassifier
from sklearn.metrics import balanced_accuracy_score
baseline = DummyClassifier(strategy="most_frequent")
baseline.fit(X_train, y_train)
score = balanced_accuracy_score(y_test, baseline.predict(X_test))
print(f"baseline balanced accuracy: {score:.3f}")Exercise
Why must a candidate and its baseline use the same test split?
Show answer
Otherwise, differences in the data rather than differences in the methods could explain the scores.