Baselines and generalisation.
Learn what a score means by comparing it with simple rules and recognising overfitting.
Start with the meaning.
A model score is meaningful only beside an alternative. For regression, a baseline might always predict the training-set mean. For classification, a baseline might always choose the most common class. A complex model that fails to improve on such a rule has not earned its complexity. The baseline also exposes class imbalance: if 95% of messages belong to one class, a model can reach 95% accuracy by saying that class every time while never recognising the rare cases we care about.
Generalisation is performance on new cases from the intended setting. Training performance measures how closely a fitted model matches the examples it learned from. A large gap between excellent training performance and weak validation performance suggests overfitting. The model learned details that do not transfer. Poor performance on both suggests underfitting or weak information: the chosen rule may be too simple, the features may lack useful signal, or the labels may be unreliable.
How the idea works.
Model complexity is not one number, but it describes how many patterns a model can represent. A shallow tree makes broad, simple divisions; a deep tree can isolate small groups and possibly memorise them. More flexibility can improve training fit while making future performance worse. Regularisation discourages overly extreme or complicated solutions. Choosing a complexity level is a validation decision, not a contest to drive training error to zero.
Learning curves compare performance as the amount of training data changes. If training is excellent and validation remains weak, more representative data may help, though it is not guaranteed. If both are poor and close together, adding more of the same data may not solve the representation problem. Better features, a different model family, or a better task definition may matter more. The curve is a diagnostic story, not an automatic prescription.
A baseline should obey the same evaluation protocol as the candidate model. It learns any necessary statistic, such as the majority class, from training data only. Comparing a candidate's test result with a baseline computed from all data gives the baseline information it should not have. The same split, metric, and population should be used for both.
Follow the code.
from sklearn.dummy import DummyClassifier
from sklearn.metrics import accuracy_score
X_train = [[1], [2], [3], [4]]
y_train = [0, 0, 0, 1]
X_test = [[5], [6]]
y_test = [0, 1]
baseline = DummyClassifier(strategy="most_frequent")
baseline.fit(X_train, y_train)
print(accuracy_score(y_test, baseline.predict(X_test)))DummyClassifier does not search for a relationship between the numeric input and the label. The most_frequent strategy learns that class 0 appears most often in y_train and predicts 0 for every test row. The test answers are 0 and 1, so one of two predictions is correct and accuracy_score returns 0.5. This is a deliberately small example showing the reference point. The numbers in X are present because the estimator interface expects feature rows, not because the baseline uses them.
If a more elaborate classifier also scores 0.5 on these two rows, the result does not establish improvement. With only two test rows, the estimate is unstable: changing one case changes the reported score by 50 percentage points. A real comparison needs enough representative cases and a metric tied to the task's costs.
What the result does not say.
Data collection can create an apparently easy shortcut. A model that predicts disease from hospital ID may exploit differences between hospitals rather than symptoms. It can score well on a random split that contains all hospitals in both sets and fail at a new hospital. Generalisation is always generalisation to a specified setting, not a universal property of an algorithm name.
Simple rules also make good explanations. When a baseline works nearly as well as a complex model, its lower cost, easier maintenance, and clearer failures may make it the better system. The goal is useful decisions, not a fashionable model.
One clear idea.
Compare every model with a simple baseline and inspect the gap between training and unseen performance.
The ML cookbook
Complete, explained Python workflows sit alongside this reading course.