Course Name : MACHINE LEARNING
Course Code : 20AM01
Course Instructor : K.Rajasekhar
Semester : VI
Regulation : R23
Unit: 2
1
UNIT-2: SYLLABUS
Nearest Neighbor-Based Models: Introduction to Proximity Measures, Distance Measures, Non-Metric Similarity Functions, Proximity Between Binary Patterns, Different Classification Algorithms Based on the Distance Measures ,K-Nearest Neighbor Classifier, Radius Distance Nearest Neighbor Algorithm, KNN Regression, Performance of Classifiers, Performance of Regression Algorithms.
Introduction to Proximity Measures (Cont’d..)
Similarity Measures
Examples:
Distance (Dissimilarity) Measures
Examples:
Measures of Feature Redundancy:
Three types of measures
Distance Measures: (cont’d)
These measures are mainly used in:
Distance Measures (Cont’d)
Euclidean Distance:
Manhattan Distance
Distance Measures (Cont’d)
Minkowski Distance:
ul for high-dimensional or sparse datasets.
Distance Measures (Cont’d)
Hamming Distance
Distance Measures (Cont’d)
Chebyshev Distance
Distance Measures (Cont’d)
Cosine Distance
Distance Measures (Cont’d)
Jaccard Distance
Non-Metric Similarity Functions
These are widely used when data is:
Cosine Similarity (Non-Metric)
(c) Cosine Similarity:
Let’s calculate the cosine similarity of x and y, where
x = (2, 4, 0, 0, 2, 1, 3, 0, 0) and y = (2, 1, 0, 0, 3, 2, 1, 0, 1).
Non-Metric Similarity Functions (Cont’d)
Pearson Correlation Similarity
Jaccard Similarity
Non-Metric Similarity Functions (Cont’d)
Overlap Coefficient (Szymkiewicz–Simpson)
Dice Similarity (Sørensen–Dice)
Proximity Between Binary Patterns
Hamming Distance (Binary Distance)
Proximity Between Binary Patterns (cont’d)
Simple Matching Coefficient (SMC)
Jaccard Similarity (for Asymmetric Binary Data)
b) Simple matching coefficient (SMC):
(c) Cosine Similarity:
Proximity Between Binary Patterns
Jaccard Distance
Dice Similarity (Sørensen–Dice)
Different Classification Algorithms Based on the Distance Measures
Nearest Neighbor Classifier (NNC):
Different Classification Algorithms Based on the Distance Measures
How It Works (Step-by-Step)
Nearest Neighbour Classifier (NNC)
, each pattern be a vector in some L dimensional space and li is its class label.
where xj is the jth training pattern and d(x, xj) is the distance between
x and xj.
Nearest Neighbour Classifier (NNC)
New Point
Point | X | Y | Class |
A | 1 | 2 | Red |
B | 3 | 1 | Blue |
C | 6 | 4 | Blue |
K-Nearest Neighbor (kNN) Algorithm
�k-Nearest Neighbors (k-NN) Classifier�
Point | X | Y | Class |
A | 1 | 2 | Red |
B | 2 | 1 | Red |
C | 5 | 4 | Blue |
D | 6 | 2 | Blue |
Distance-Weighted k-Nearest Neighbors (DW-kNN)
Why Use Distance Weighting?
Working of Distance-Weighted k-NN (Step-by-Step)
Distance-Weighted k-Nearest Neighbors (DW-kNN)
Distance-Weighted k-Nearest Neighbors (DW-kNN)
Point | X | Y | Class |
A | 1 | 2 | Red |
B | 2 | 1 | Red |
C | 5 | 4 | Blue |
D | 6 | 2 | Blue |
Distance-Weighted k-Nearest Neighbors (DW-kNN)
Advantages of Distance-Weighted k-NN
✔ Reduces impact of far-away neighbors�✔Improves accuracy over normal k-NN�✔ Better decision boundaries�✔ Works well with small and moderate datasets
.
Radius Distance Nearest Neighbor (RDNN)
Radius Distance Nearest Neighbor (RDNN)
Point | X | Y | Class |
A | 1 | 2 | Red |
B | 2 | 1 | Red |
C | 5 | 4 | Blue |
D | 6 | 2 | Blue |
Radius Distance Nearest Neighbor (RDNN)
Radius distance Near Neighbours Algorithm
Class assigned to T is Class 3
KNN Regression
How KNN Regression Works (Step-by-Step)
Query:
KNN Regression
Example of KNN Regression
House Size (sq ft) | Price (lakhs) |
800 | 50 |
1000 | 65 |
1200 | 70 |
1500 | 85 |
KNN Regression
to find the value of y for a new vector x.
Performance of Classifiers:
Confusion Matrix
A confusion matrix is a table used for evaluating classifier performance.
| Predicted Positive | Predicted Negative |
Actual Positive | True Positive (TP) | False Negative (FN) |
Actual Negative | False Positive (FP) | True Negative (TN) |
Performance of Classifiers:
Accuracy
Accuracy= (TP + TN)/(TP+TN+FP+FN)
Precision
Precision= (TP)/(TP+FP)
Recall (Sensitivity)
Recall=(TP)/(TP+FN)
F1-Score
F1=2× (Precision⋅ Recall)/(Precision + Recall)
2.5 EVALUATING PERFORMANCE OF A MODEL
2.5 EVALUATING PERFORMANCE OF A MODEL Cont…
2.5 EVALUATING PERFORMANCE OF A MODEL Cont…
2.5 EVALUATING PERFORMANCE OF A MODEL Cont…
2.5.1 Supervised learning – Classification
2.5 EVALUATING PERFORMANCE OF A MODEL Cont…
2.5.1 Supervised learning – Classification
In context of the above confusion matrix, total count of TPs= 85,
count of FPs = 4, count of FNs = 2 and count of TNs = 9.
2.5 EVALUATING PERFORMANCE OF A MODEL Cont…
2.5.1 Supervised learning – Classification
2.5 EVALUATING PERFORMANCE OF A MODEL Cont…
2.5.1 Supervised learning – Classification
Precision:
Recall:
2.5 EVALUATING PERFORMANCE OF A MODEL Cont…
2.5.1 Supervised learning – Classification
F-Measure
In context of the confusion matrix for the cricket match win prediction problem,
Performance of Regression Algorithms
Mean Absolute Error (MAE)
Mean Squared Error (MSE):
Performance of Regression Algorithms
Root Mean Squared Error (RMSE)
Square root of MSE → gives error in original units (like dollars, meters).
Most commonly used regression metric.
R² Score (Coefficient of Determination):
Where:
SSres = Sum of squared residuals
SStot = Total variance in data
Interpretation:
Performance of Regression Algorithms
Adjusted R² Score
Adjusts R² based on number of predictors (k).
Useful in multiple regression.
Prevents artificially high R² due to adding many features