Face Recognition using KNN
A supervised machine learning algorithm is one that relies on labeled input data to learn a function that produces an appropriate output when given new unlabeled data. ex => K Nearest Neighbours
KNN is a lazy learning, non-parametric algorithm. It uses data with several classes to predict the classification of the new sample point. KNN is non-parametric since it doesn’t make any assumptions on the data being studied, i.e., the model is distributed from the data.
KNN is very simple and is often used as a benchmark for more complex classifiers like the Support Vector Machines (SVM) and the Artificial Neural Networks (ANN).
Working of KNN Algorithm in Machine Learning
To understand better the working KNN algorithm applies the following steps when using it:
Step 1 — When implementing an algorithm, you will always need a data set. So, you start by loading the training and the test data.
Step 2 — Choose the nearest data points (the value of K). K can be any integer.
Step 3 — Do the following, for each test data –
3.1 — Use Euclidean distance, Hamming, or Manhattan to calculate the distance between test data and each row of training. The Euclidean method is the most used when calculating distance.
3.2 — Sort data set in ascending order based on the distance value.
3.3 — From the sorted array, choose the top K rows.
3.4 — Based on the most appearing class of these rows, it will assign a class to the test point.
Step 4 — End
‘Birds of same feather flock together’ well justifies KNN algorithm.
Our Task: To generate some real time training data by taking some selfies from webcam
Preparing training dataset with the selfie model
# Loading data and training: