2. Carefully explain the differences between the KNN classifier and KNN
library(knitr)
library(kableExtra)
# Create a data frame
knn_table <- data.frame(
"KNN classifier" = c("Response variable is categorical",
"Uses majority vote among its nearest K neighbors to predict class for new observation",
"Neighbors vote their own class, and the most common is assigned as the predicted label"),
"KNN regression" = c("Response variable is continuous",
"The predicted value is computed as the weighted average of the K nearest neighbors response value",
"Closer neighbors contribute more to the prediction if weights are used")
)
# Generate the table
kable(knn_table, align = "l", booktabs = TRUE, escape = FALSE) %>%
kable_styling(full_width = FALSE)
| KNN.classifier | KNN.regression |
|---|---|
| Response variable is categorical | Response variable is continuous |
| Uses majority vote among its nearest K neighbors to predict class for new observation | The predicted value is computed as the weighted average of the K nearest neighbors response value |
| Neighbors vote their own class, and the most common is assigned as the predicted label | Closer neighbors contribute more to the prediction if weights are used |