Lab 07
Lab 07
Background
Go to terminal in Pycharm
Type pip install pandas
Or you can install all by going to Settings Project Interpreter + sklearn Install
Package
KNN- Classifier
In pattern recognition and machine learning, k-nearest neighbors (KNN) is a simple algorithm
that stores all available cases and classifies new cases based on a similarity measure (e.g.
distance). KNN is a non-parametric method where the input consists of the k closest training
examples in the feature space. The output is a class membership. An object is classified by a
majority vote of its neighbors, with the object being assigned to the class most common among
its k nearest neighbors (k is a positive integer, typically small). If k = 1, then the object is simply
assigned to the class of that single nearest neighbor.
KNN Classification Model
Algorithm: KNearestNeighbors
Input: Training data X
Training data labels Y
Sample x to classify
Output: Decision y p about sample x
for i ← 1 to m do
Compute distance between training sample X i and unlabeled sample x i.e. d( X i , x)
end for
Compute the decision class y pby measuring the majority label Y from I
return y p
Example
Fit does training on Training Data (X_train, Y_Train)