0
0
ML Pythonprogramming~5 mins

K-Nearest Neighbors (KNN) in ML Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the basic idea behind the K-Nearest Neighbors (KNN) algorithm?
KNN predicts the label of a new data point by looking at the labels of the closest K points in the training data and choosing the most common label among them.
Click to reveal answer
beginner
How does KNN decide which points are 'nearest'?
KNN uses a distance measure, usually Euclidean distance, to find the closest points to the new data point.
Click to reveal answer
beginner
What role does the parameter 'K' play in KNN?
The parameter 'K' determines how many neighbors to look at when making a prediction. A small K can be noisy, while a large K smooths the prediction.
Click to reveal answer
intermediate
Why is it important to scale features before using KNN?
Because KNN uses distance to find neighbors, features with larger scales can dominate the distance calculation. Scaling puts all features on the same scale so each contributes fairly.
Click to reveal answer
intermediate
What is a common problem with KNN when the dataset is very large?
KNN can be slow because it needs to calculate distances to all training points for each prediction, which takes more time as the dataset grows.
Click to reveal answer
What does the 'K' in K-Nearest Neighbors represent?
AThe number of closest points considered for prediction
BThe number of features in the dataset
CThe number of classes in the target
DThe number of training samples
Which distance metric is most commonly used in KNN?
AManhattan distance
BJaccard index
CCosine similarity
DEuclidean distance
Why should features be scaled before applying KNN?
ATo make the model faster
BTo ensure all features contribute equally to distance
CTo reduce the number of features
DTo increase the number of neighbors
What happens if you choose a very small K in KNN?
AThe model becomes more stable
BThe model ignores neighbors
CThe model may be sensitive to noise
DThe model always predicts the majority class
Which of these is a drawback of KNN?
AIt can be slow on large datasets
BIt requires training a complex model
CIt cannot handle multiple classes
DIt always overfits
Explain how K-Nearest Neighbors makes a prediction for a new data point.
Describe why feature scaling is important when using KNN.