Machine Learning Algorithm Quizzes

KNN

Question 1

KNN is often referred to as a 'lazy learner' or 'instance-based' algorithm. Why?

Question 2

Because KNN relies on calculating distances between data points, __ is a critical data preprocessing step to ensure that all features contribute equally to the distance metric.

Your answer here.

Question 3

Which line of code correctly imports the K-Nearest Neighbors model for a classification task from scikit-learn?

Question 4

Select all the likely consequences of choosing the value of 'k' (the number of neighbors) in a KNN model.

Question 5

When using KNeighborsRegressor to predict a continuous value for a new data point, how is the prediction calculated?

Question 6

In scikit-learn's KNeighborsClassifier, the most important hyperparameter, which specifies the number of neighbors to use, is called __________.

Your answer here.

Question 7

Which of the following are true statements about the KNN algorithm?

Question 8

You have built a KNeighborsClassifier with n_neighbors=5. To predict the class of a new data point, the model finds the 5 nearest neighbors in the training data. If 3 of these neighbors belong to Class A and 2 belong to Class B, what will the model predict (assuming weights='uniform')?

Question 9

When instantiating KNeighborsClassifier, you can set the weights parameter to 'distance'. What effect does this have?

End of Quiz

Your final score is: 0 / 0

List of Questions

Question 1: KNN is often referred to as a 'lazy learner' or 'instance-based' algorithm. Why?

Answers: It memorizes the entire training dataset and does no 'learning' until a prediction is requested..

Question 2: Which line of code correctly imports the K-Nearest Neighbors model for a classification task from scikit-learn?

Answers: from sklearn.neighbors import KNeighborsClassifier.

Question 3: Select all the likely consequences of choosing the value of 'k' (the number of neighbors) in a KNN model.

Answers: A very small 'k' (e.g., k=1) can lead to a model with high variance and sensitivity to noise (overfitting)., A very large 'k' (e.g., k=number of samples) can lead to a model with high bias that underfits the data..

Question 4: When using `KNeighborsRegressor` to predict a continuous value for a new data point, how is the prediction calculated?

Answers: By taking the average of the target values of the 'k' nearest neighbors..

Question 5: Which of the following are true statements about the KNN algorithm?

Answers: Prediction time can be slow for large datasets., It is a non-parametric model, making it flexible for complex decision boundaries..

Question 6: You have built a `KNeighborsClassifier` with `n_neighbors=5`. To predict the class of a new data point, the model finds the 5 nearest neighbors in the training data. If 3 of these neighbors belong to Class A and 2 belong to Class B, what will the model predict (assuming `weights='uniform'`)?

Answers: Class A.

Question 7: When instantiating `KNeighborsClassifier`, you can set the `weights` parameter to 'distance'. What effect does this have?

Answers: It gives more influence to closer neighbors when taking the majority vote..