This project explores the implementation and comparison of K-Nearest Neighbors (KNN) classification algorithm on the Iris dataset. It compares the performance of standard KNN classifier with custom implementations using different scaling techniques.
- Python 3.x
- Clone the repository or download the project files.
- Navigate to the project directory.
- Create and activate a virtual environment:
python3 -m venv venv_name source venv_name/bin/activate # For Linux/Mac venv_name\Scripts\activate.bat # For Windows
- Install the required libraries using the provided
requirements.txt
file:pip install -r requirements.txt
- After activating the virtual environment, run the
main.py
file:python main.py
main.py
: Main script containing the implementation of KNN classifier and its comparison.README.md
: This file providing an overview of the project.requirements.txt
: File containing the list of required libraries.
The code performs the following steps:
- Imports necessary libraries and modules.
- Loads the Iris dataset.
- Performs Principal Component Analysis (PCA) for dimensionality reduction.
- Splits the dataset into training and testing sets.
- Implements custom functions for KNN algorithm: distance calculation, finding nearest neighbors, and voting.
- Compares the performance of KNN with different values of K (3, 5, 7) using standard and custom implementations.
- Prints the accuracy scores for each variation.
The script prints out the accuracy scores of KNN classifiers with different configurations including:
- Standard KNN with different values of K.
- Custom KNN with different scaling techniques (StandardScaler and Normalizer) and different values of K.
This project is licensed under the MIT License - see the LICENSE
file for details.