Edd's Knowledge Base

Simple comparison table:

NOTE: When evaluating a model, make sure not to forget the following:

  1. Compare training metrics vs. test metrics (measure of under/overfitting)

  2. Compare test metrics vs. baseline metrics (measure of how well the model works, use the test set when calculating the baseline)

Baseline calculation for regression tasks : where is the mean of values (the baseline is we are assuming the prediction is always the mean value of the training set). For classification tasks, you can use the default ratios. For example if 60% of the rows are of the positive class (1), then the baseline accuracy is 60% (meaning that even if you pick randomly from the dataset you can’t do worse then 60%, your model shouldn’t do worse too!).

For every model you train, do not forget to compare the results with the baseline!

Never train the model and tune hyper-parameters using the testing set. It leads to bad generalization! In other words, split your testing set in the beginning and never touch it until the end (create a validation set instead).

Classification Metrics

Pred/Actual01
0True Negative (TN)False Negative (FN)
1False Positive (FP)True Positive (TP)

Accuracy: The proportion of correct predictions out of all predictions. It’s a good starting point but can be misleading with imbalanced datasets.

Precision: The ratio of correctly predicted positive observations to the total predicted positive observations. A high precision means your model has a low number of false positives.

Recall (or Sensitivity): The ratio of correctly predicted positive observations to all observations in the actual class. A high recall means your model has a low number of false negatives.

F1-Score: The harmonic mean of Precision and Recall. It provides a single score that balances both metrics, which is especially useful for imbalanced datasets.

When to Choose F1

Choose F1 when both false positives and false negatives matter and the classes are imbalanced.

  • Versus accuracy: accuracy counts true negatives, so a rare positive class barely moves it. With 2% positives, a model that always predicts negative scores 98% accuracy but an F1 of 0, since F1 ignores true negatives.
  • Versus precision or recall alone: each can be gamed. Predicting positive only for the single surest case gives high precision and near-zero recall; predicting everything positive gives 100% recall and precision equal to the prevalence. The harmonic mean sits close to the smaller of the two, so F1 is high only when both are: precision 0.9 and recall 0.1 average to 0.5 arithmetically but give an F1 of about 0.18.
SituationBetter choice
Rare positive class that matters (fraud, screening, defects, alerts), or abundant uninformative true negatives (information retrieval)F1
Balanced classes with equal error costsAccuracy
False positives much worse (spam filter blocking real mail)Precision, or
False negatives much worse (disease screening)Recall, or
Performance across all thresholdsROC AUC or average precision (ROC and AUC Curves)
Trustworthy probabilitiesBrier score and calibration (Probability Calibration)
Several classesMacro-F1 (classes equal) or micro-F1 (large classes dominate)

The general form is , where sets how much more recall matters than precision. Limits of F1: it depends on one threshold, ignores true negatives, weights precision and recall equally unless is used, and says nothing about probability quality.


Clustering Metrics

Unsupervised models need different metrics (purity, Rand Index, ARI, NMI, silhouette); see Clustering Evaluation Metrics.


Regression Metrics

To be continued…


Bias and Variance


Underfitting and Overfitting

Underfitting:

  • Low-dimensional
  • Heavily regularized
  • Bad modeling assumption

Note: High bias = Model consistently misses relevant patterns (underfitting)

Overfitting:

  • High dimensional or non-parametric
  • Weakly regularized
  • Not enough data

Note: High variance = Model is overly sensitive to training data (overfitting)


Regularization

See Regularization for a full treatment.

Core idea: For any model with parameters :

  • L1 Regularization: Add
  • L1 Constraint
  • L2 Regularization: Add
  • Elastic Net