14. Classification#
This chapter introduces classification as supervised machine learning for category prediction. You will study rule-based classifiers, nearest neighbors, and how to judge a classifier honestly with training and test sets, using real online-shopping sessions and business cases such as fraud and purchase prediction. Chapter 15 continues with scikit-learn, evaluating classifiers beyond accuracy, and logistic regression.
Classification: Predicting a category, such as fraud or not fraud, for a new observation by learning from past labeled examples.
Nearest Neighbors: A new case gets the label of the most similar training examples, with similarity measured by distance between features.
Scaling Features: Distance adds up differences across features, so features on large scales dominate unless all are put on a comparable scale, using training-set statistics only.
Training and Test Sets: A classifier must be judged on test data it has not seen, because it looks unrealistically good on its own training data.
Accuracy: The share of test cases classified correctly, compared with a baseline that always predicts the most common class.
Chapter Video
Video credit: CrashCourse. (2018, October 31). Supervised Machine Learning: Crash Course Statistics #36. YouTube. Watch on YouTube (11:50).
This embedded video is provided for educational reference only. All rights are retained by the respective copyright holder.
Learning Objectives
By the end of this chapter, you will be able to:
Distinguish classification from regression and clustering.
Use labeled examples to predict categorical outcomes, such as whether a shopping session ends in a purchase.
Explain nearest-neighbor classification with distance, standard units, and a majority vote.
Measure a classifier’s test accuracy and compare it with a baseline that always predicts the most common class.
Separate training, validation, and test data when building and evaluating a classifier, and use a validation set to choose k.
Chapter Flow
Glossary
# |
Term |
Explanation |
|---|---|---|
1 |
Classification |
Predicting a categorical label for an observation. |
2 |
Classifier |
A model or rule that assigns labels. |
3 |
Label |
The category being predicted. |
4 |
Feature |
An input variable used for prediction. |
5 |
Training data |
Labeled data used to build a classifier. |
6 |
Test data |
Labeled data reserved for evaluation. |
7 |
Supervised learning |
Learning from examples with known labels. |
8 |
Row of a table |
One observation or case in a dataset. |
9 |
Nearest neighbor |
A classifier that predicts from the most similar example. |
10 |
k-nearest neighbors |
A classifier that predicts the majority label among the k most similar training examples. |
11 |
Majority vote |
Predicting the most common label among the nearest neighbors. |
12 |
Distance |
A numeric measure of dissimilarity between observations. |
13 |
Similarity |
How alike two observations are according to selected features. |
14 |
Feature space |
The coordinate system formed by model features. |
15 |
Decision boundary |
The edge between decision regions, where the predicted label changes. |
16 |
Standard units |
A value expressed as the number of SDs above or below the average. |
17 |
Validation |
Checking model choices using held-out data. |
18 |
Overfitting |
When a classifier matches training data too closely. |
19 |
Generalization |
Performance on new data beyond the training sample. |
20 |
Accuracy |
The fraction of cases whose predicted label equals the actual label. |
21 |
Error rate |
The fraction of test cases classified incorrectly. |
22 |
Baseline classifier |
A rule that ignores the features, such as always predicting the most common class, used as a point of comparison. |
23 |
Rule-based classifier |
A classifier made of a rule written by a person, such as predicting purchase when page value is above 0. |
24 |
Training accuracy |
The share of training cases a classifier gets right; optimistic, because the classifier has seen those cases. |
25 |
Test accuracy |
The share of held-out test cases classified correctly; the honest estimate for new cases. |
26 |
Data leakage |
Information the model would not have at prediction time getting into how it is built or tested, such as scaling with test-set statistics or using an attribute known only after the outcome. |
27 |
Underfitting |
When a classifier is too simple to capture the pattern in the data, such as a nearest neighbor classifier with a very large k that always predicts the majority class. |