A matlab implementation for the K-nearest neighbor algorithm (KNN) with K-fold cross validation. This implementation was part of our coursework.
For calculating data accuracy. I've used 3 different formulas for nearest neighbor distance calculation and did the k-fold cross validation for each of them.
- Manhattan Distance
- Chebychev Distance
- Euclidean Distance
The KNN is implemented for K=5, K=10 and K=15 respectively.
You can simply run the program by importing the dataset given in circular.txt and passing it to the KNN_crossvalidation function. Using the following statements.
KNN_crossvalidation(importdata(path_to_circular.txt))
The exercise sheet is given for your ease to understand what we were required to accomplish and how. This is the implementation for the first two questions mentioned in exercise.pdf.
I've also uploaded the topic slides, if anyone is interested in understanding the topic.
Copyright © 2018 Muazzam Ali
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.