KNN for multiclass classification
Constructing a KNN multiclass model is quite straightforward since it involves no special extensions to the algorithm, such as those needed to adapt logistic regression to targets with more than two values. We can see this by working with the same machine failure data that we worked with in the Multinomial logistic regression section of Chapter 10, Logistic Regression.
Note
This dataset on machine failure is available for public use at https://www.kaggle.com/datasets/shivamb/machine-predictive-maintenance-classification. There are 10,000 observations, 12 features, and two possible targets. One is binary and specifies whether the machine failed or did not. The other contains types of failure. The instances in this dataset are synthetic, generated by a process designed to mimic machine failure rates and causes.
Let’s build our machine failure type model:
- First, let’s load the now-familiar modules:
import pandas as pd...