5 Classification
Understand how classification assigns category labels, how common classifiers make predictions, and how probability estimates and decision thresholds affect those predictions.
What predicts
is a supervised learning task: a model learns from examples whose category labels are known, then uses example features to predict labels for new examples. For instance, an email classifier can use words and sender details to predict whether a message is spam or not spam.
Unlike regression, which predicts a numerical value, predicts one or more categories. The kind of task depends on how many labels are possible and whether an example can receive more than one label.
Types of
In , there are two possible labels. Predicting whether an email is spam or not spam is an example.
In , each example receives one of three or more mutually exclusive labels. For example, a fruit might be classified as an apple, orange, or pear.
In , one example can receive several labels at once. A photo, for example, might be tagged both beach and sunset.
Common classifiers
Classifiers differ in how they use training examples to distinguish categories:
Logistic regression learns a weighted relationship between features and classes. Despite its name, it is commonly used for and can estimate class probabilities as well as predict labels.
Decision trees make a sequence of feature-based decisions, such as checking whether a message is from an unknown sender. Their resulting rules can be easy to inspect.
Random forests combine predictions from many decision trees. This often improves accuracy and helps control overfitting.
Support vector machines (SVMs) seek a boundary that separates classes with a wide margin. Kernels can represent more complex boundaries.
K-nearest neighbors (KNN) predicts from the labels of nearby training examples, typically using a majority vote.
estimates class probabilities using Bayes’ theorem and a simplifying assumption that features are conditionally independent given the class. It is often used for text, including spam filtering.
No classifier is best for every dataset. A suitable choice depends on the data, the task, and practical needs such as speed and interpretability.
Labels and
A classifier can return a , meaning its selected label, or for the possible labels. For example, a spam model might estimate a probability of for spam and for not spam. A multiclass model might estimate probabilities of for apple, for pear, and for orange. For mutually exclusive classes, the estimates sum to .
A predicted probability is an estimate, not a guarantee. Not every classifier provides probabilities directly, and can be poorly calibrated: predictions assigned a probability of do not necessarily prove correct of the time. , for example, can classify effectively while producing that should be treated cautiously.
How thresholds change labels
In , a model may use a to turn the estimated probability of the positive class into a label. With a threshold of , an estimated spam probability of produces the label spam.
A different threshold may be appropriate when the costs of mistakes differ. For example, a medical screening system may use a lower threshold to reduce missed positive cases. Changing the threshold changes the label predictions, even though the underlying probabilities remain the same.