3 Classification Fundamentals

Learn how classification uses labeled examples, how to evaluate performance on unseen data, and how to interpret common binary-classification metrics.

as supervised learning

is a supervised learning task. A model learns from examples that include input data and known category labels, then predicts a category for a new example.

A task with two possible categories is ; one with three or more categories is . A classifier may produce a probability or score for each category, and a decision rule—often a threshold—turns that score into a predicted class.

Examples, , and labels

A dataset consists of examples. Each example has , which are the input information used to make a prediction, and a , which is the correct category the model is meant to predict. For an email, might include its text, sender, or number of links; its might be spam or not spam.

During training, the model uses examples’ and labels to learn patterns connecting inputs to categories. At prediction time, it receives for a new example and estimates its . should be available when the prediction is made. Accidentally including information that reveals the answer is and can make evaluation misleading.

Training and

is used to fit the model. is held back until the model is ready and used to estimate how well it handles unseen examples.

Testing on training examples can give an overly optimistic result: a model may memorize those examples without learning patterns that generalize. Keep test examples separate from training, and avoid repeatedly using the test set to make modeling decisions. If a validation set is used to select settings or compare models, reserve the test set for a final evaluation.

Where appropriate, stratified splitting can help preserve class proportions across sets. Data with time order or related groups may need a split that respects that structure.

Understanding the

For a binary classifier, first choose one class as the positive class. Compare each prediction with the known to count four outcomes:

  • True positive (TP): A positive example correctly predicted positive.

  • False positive (FP): A negative example incorrectly predicted positive.

  • True negative (TN): A negative example correctly predicted negative.

  • False negative (FN): A positive example incorrectly predicted negative.

A contains these counts. It shows both how many predictions were wrong and what kinds of errors occurred.

Calculating and choosing metrics

Common metrics summarize different aspects of binary- performance. Using the counts from the , calculate them as follows:

  • is the fraction of all predictions that are correct.

Accuracy=TP+TNTP+TN+FP+FN\mathrm{Accuracy} = \frac{TP + TN}{TP + TN + FP + FN}
  • is the fraction of predicted-positive examples that truly are positive. High means fewer false alarms.

Precision=TPTP+FP\mathrm{Precision} = \frac{TP}{TP + FP}
  • is the fraction of actual positive examples the model correctly identifies. High means fewer missed positives.

Recall=TPTP+FN\mathrm{Recall} = \frac{TP}{TP + FN}
  • is the harmonic mean of and . It provides a single summary that is low when either or is low.

F1=2×Precision×RecallPrecision+RecallF1 = 2 \times \frac{\mathrm{Precision} \times \mathrm{Recall}}{\mathrm{Precision} + \mathrm{Recall}}

For an email classifier with TP=8TP = 8, FP=2FP = 2, FN=4FN = 4, and TN=6TN = 6, is 1420=70%\frac{14}{20} = 70\%, is 810=80%\frac{8}{10} = 80\%, is 812≈66.7%\frac{8}{12} \approx 66.7\%, and the is approximately 72.7%72.7\%.

No single metric is best for every task. can conceal poor performance when one class is much more common than another. is especially relevant when false positives are costly, while matters when missing positive cases is costly. Choose a metric or balance of metrics in light of the consequences of each type of error.