L3 Flashcards

(36 cards)

1
Q

What type of learning does KNN fall under?

A

Supervised Learning

  • learning algorithm provided with input-output pairs

KNN uses input-output pairs for classification and regression tasks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two main tasks of Supervised Learning?

A
  • Classification: Output discrete, e.g. class labels.
  • Regression: Output continuous, e.g. predicting a value like salary or temperature.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does KNN stand for?

A

K-Nearest Neighbors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a defining characteristic of KNN as a learning algorithm?

A

Non-parametric, instance-based, lazy learning algorithm.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does ‘non-parametric’ mean in the context of KNN?

A

Makes no assumptions about the form of the mapping function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does ‘lazy learning’ imply in KNN?

A

No explicit training phase; algorithm stores the entire dataset and computes output only when a query is made.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does KNN classify or predict the output for a new data point?

A
  1. Compute distance between the new point and all points in the training dataset.
  2. Identify the k nearest training examples
  3. Use these neighbors to determine the output:
    - Classification: Take the majority vote
    - Regression: Take the mean (or sometimes median) of the target values.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the method used by KNN for classification?

A

Take the majority vote of the k nearest training examples.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

For regression in KNN, what is the method used to determine the output?

A

Take the mean (or sometimes median) of the target values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a decision boundary in KNN?

A

A line or curve that separates different classes in the feature space.

  • Linear: Formed in simple models (e.g., logistic regression).
  • Non-linear: Formed in KNN with low k due to sensitivity to local data patterns.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What happens to the decision boundary in KNN with low k?

A

Forms a complex boundary, leading to overfitting.

  • KNN forms complex and non-linear boundaries depending on the value of k and data distribution.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What happens to the decision boundary in KNN with high k?

A

Forms a smooth boundary, leading to underfitting.

  • KNN forms complex and non-linear boundaries depending on the value of k and data distribution.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between classification and regression in KNN?

A
  • Classification: Assign class label; model trained from the data defines a decision boundary that separates the data; discrete labels (e.g. cat / dog); based on majority vote of neighbours
  • Regression: Predict numeric target; model fits the data to describe the relation between 2 features or between a feature (e.g., height) and the label (e.g., yes/no); based on average of neighbour values
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the hyperparameter k in KNN?

A

Represents the number of labeled neighbors to consider.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the risk associated with a small value of k (e.g., k=1)?

A

High variance, very flexible, risk of overfitting.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the risk associated with a large value of k (e.g., k=N)?

A

Low variance, oversmooth, risk of underfitting.

**k = N: since all datapoints are considered, the predicted label for a test point will always be the the majority label of all datapoints. Equivalent to a majority classifier.

17
Q

What is the effect of ties in KNN classification?

A

Random selection from the tied labels is common.

**Ties: in case of a tie between predicted labels, there are different possibilities. The most common one is random selection from the tied labels.

18
Q

What is the recommended value for k in relation to the number of training samples?

A

Generally, k = √n (n = number of training samples).

**Use odd values for binary classification to avoid ties.
**Use cross-validation on a validation set to choose optimal k.

19
Q

What distinguishes weighted KNN from standard KNN?

A

In standard KNN, each neighbor contributes equally VS In weighted KNN, neighbors closer to the test point contribute more to the decision.

Effect: Improves performance, especially when data is dense and neighbors vary in quality.
**with distance weighting, k=n is no longer equivalent to a majority based classifier

20
Q

What are the types of weighting used in weighted KNN?

A
  • Inverse distance - each point has a weight equal to the inverse of its distance to the point to be classified (neighboring points have a higher vote)
  • Inverse squared distance
  • Kernel functions (e.g., Gaussian kernel)
21
Q

What does the distance function determine in KNN?

A

How ‘closeness’ is measured between points.

22
Q

What are the two distance types mentioned in KNN?

A
  • Euclidean - straight line (use for continuous numeric data) –> sqrt (x2-x1)^2 + (y2-y1)^2
  • Manhattan - dist btwn projections on axis (x_1 - x_2)

Effect:
Different distance metrics can change which points are considered neighbors.
Affects classification and regression outcomes.

23
Q

What is the Nearest Centroid Classifier?

A

For each class, compute the centroid (mean vector of all feature values) and classify new instances into the class whose centroid is closest (using Euclidean distance).

24
Q

What is the purpose of the Nearest Shrunken Centroid?

A

To reduce the effect of irrelevant or noisy features.

  • Each class centroid is shrunk toward the overall mean by a threshold.
  • Helps reduce the effect of irrelevant or noisy features.
  • Common in high-dimensional spaces, e.g., gene expression, text data
25
What is the effect of the Curse of Dimensionality on KNN?
As the number of features increases, distance between points becomes less meaningful Distance between points becomes less meaningful. All points appear to be at a similar distance. KNN performance deteriorates. Example: 1 feature: 10 values → 10 combinations 2 features: 10 × 10 = 100 combinations 3 features: 1000 combinations ➤ Exponential growth of feature space.
26
What is KNN's approach for missing value imputation?
Identifying k nearest rows and filling missing value using the mean or mode. ✔ Particularly effective when the feature with missing values is strongly correlated with others.
27
What is the effect of low k on model complexity?
High complexity, fits noise; low bias and high variance.
28
What is the effect of high k on model complexity?
Low complexity, smooth model; high bias and low variance.
29
What is a significant advantage of KNN?
1. No training phase; just stores the data. 2. Adaptable to all types -> Handles both classification and regression 3. Works with non-linear data -> Captures complex patterns using local neighborhoods 4. Easy to implement -> Algorithm is straightforward 5. Flexible distance metric -> Custom distance functions for different data types
30
What is a significant disadvantage of KNN?
1. High computation during inference; must compute distance to every training sample. 2. No interpretability -> No clear model or decision rule 3. Sensitive to noisy data -> Especially when k is small 4. Poor in high dimensions -> Suffers from the curse of dimensionality 5. Requires feature scaling -> Features must be on the same scale (e.g., standardization or normalization)
31
What does KNN require for feature scaling?
Features must be on the same scale (e.g., standardization or normalization).
32
What about tuning for model complexity and generalization
- Use cross-validation to select k that generalizes well. - Don’t evaluate performance on the test set while tuning → data leakage.
33
What does overfitting mean in terms of k?
Very small k, high sensitivity to noise; Poor generalization
34
What does underfitting mean in terms of k?
Very large k, too smooth boundary; Misses important patterns
35
What is Nearest-neighbour classifier?
Given a set of labeled instances (training set), new instances (test set) are classified according to their nearest labeled neighbour
36
What is KNN regression?
Instead of voting → Predict a continuous value by averaging the target values of the k-nearest neighbors. **k-NN classification combines the discrete predictions of k-neighbours / k-NN regression combines continuous predictions / k-NN regression fits the best line between the neighbors