liveBook · Manning

Classifier

As explained in Grokking Machine Learning

A supervised-learning technique that assigns an example to one or more discrete categories.

Is this email spam or not? A classifier learns from examples with known labels, then predicts a category for a new example. Here, each email is an example, its words or other properties are features, and “spam” or “ham” is its label. This is supervised learning because the training examples come with labels. section 2.2 section 5.5

A classifier predicts a category, not an unrestricted number. A house-price model predicts a number and is therefore a regression model. Many classifiers answer a yes-or-no question, but a classifier can also choose among several categories, such as animal types or apps to recommend. section 2.2 section 5.0

Different classifiers turn features into predictions in different ways:

  • A perceptron gives each feature a weight, adds a bias, and predicts yes when the resulting score is at least zero. For sentence sentiment, words can receive positive or negative scores. Visually, the model tries to separate two classes of points with a line. section 5.6
  • Naive Bayes estimates a label’s probability from observed features. In a spam filter, words provide evidence that changes the estimated probability that an email is spam. section 8.0 section 8.2
  • A decision tree asks questions about features and predicts from the answers. At a leaf, it can choose the most common label among the training examples that reached it. section 9.2 section 9.8

Which question makes a better classifier?

Suppose you can ask app users only one question before predicting which app they downloaded. Splitting six training examples by platform gives four correct predictions; splitting by age gives five. Accuracy—the fraction of examples classified correctly—favors age on this dataset. A decision tree can continue splitting a group when another question helps separate its labels. section 9.2

Figure 9.9 Classifier 1 uses platform, and classifier 2 uses age. To make the prediction at each leaf, each classifier picks the most common label among the samples in that leaf. Classifier 1 is correct four out of six times, and classifier 2 is correct five out of six times. Therefore, based on accuracy, classifier 2 is better.

Compare the platform and age splits: each leaf predicts its most common label, making the difference in accuracy visible. section 9.2

To try this yourself, take a small labeled set of emails. Pick one feature, such as whether an email contains a particular word, and make a simple spam-or-ham rule. Count how often it predicts the recorded labels correctly. Then try another feature and compare the counts; deciding which rule works best is part of building a useful classifier. section 1.3 section 9.2

How Grokking Machine Learning covers it

How deep it goes
Develops weighted-score, probability-based, and question-splitting classifiers, then compares decision-tree splits using accuracy, Gini impurity, and entropy.
Examples
Uses spam emails, sentence sentiment, animal labels, and app-download records to illustrate category predictions.
What it assumes
Introduces labels, numerical and categorical data, and features before using scores and probabilities; assumes no specialist background in its opening examples.
What you can do after
Build it from scratch by scoring features with a perceptron or splitting labeled examples with a decision tree, then compare predictions.
How it connects
Connects supervised learning and features to regression, perceptrons, naive Bayes, decision trees, and accuracy.

Also explained in

Compare how 31 books explain classifier →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Machine Learning. The section links point to the parts of the book it draws on.