{"id":28003571,"url":"https://github.com/mahdikh03/knn-algorithm-on-irisdataset","last_synced_at":"2025-05-09T02:13:10.996Z","repository":{"id":254436522,"uuid":"846531544","full_name":"MahdiKh03/kNN-Algorithm-on-IrisDataset","owner":"MahdiKh03","description":"A machine learning project to implement the K-Nearest Neighbors (KNN) algorithm from scratch using Python for classification on the Iris dataset.","archived":false,"fork":false,"pushed_at":"2025-04-22T12:56:23.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-09T02:13:08.070Z","etag":null,"topics":["iris-dataset","knn-classification","machine-learning"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MahdiKh03.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-23T12:09:38.000Z","updated_at":"2025-04-22T12:56:27.000Z","dependencies_parsed_at":"2024-08-23T13:30:50.191Z","dependency_job_id":"30fcd180-3394-4927-873f-bd248be8412a","html_url":"https://github.com/MahdiKh03/kNN-Algorithm-on-IrisDataset","commit_stats":null,"previous_names":["mahdikh03/knn-algorithm-on-irisdataset"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MahdiKh03%2FkNN-Algorithm-on-IrisDataset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MahdiKh03%2FkNN-Algorithm-on-IrisDataset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MahdiKh03%2FkNN-Algorithm-on-IrisDataset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MahdiKh03%2FkNN-Algorithm-on-IrisDataset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MahdiKh03","download_url":"https://codeload.github.com/MahdiKh03/kNN-Algorithm-on-IrisDataset/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253176448,"owners_count":21866143,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["iris-dataset","knn-classification","machine-learning"],"created_at":"2025-05-09T02:13:10.495Z","updated_at":"2025-05-09T02:13:10.991Z","avatar_url":"https://github.com/MahdiKh03.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# K-Nearest Neighbors (KNN) Classifier on Iris Dataset\n\nThis Python script implements a basic K-Nearest Neighbors (KNN) classifier using the famous Iris dataset. The script performs the following steps:\n\n1. **Load the Dataset**: The Iris dataset is loaded using Pandas, and the data is split into training and testing sets.\n2. **Data Preprocessing**: The dataset is divided randomly into training and testing sets. Each item is then numbered for easy tracking.\n3. **Distance Calculation**: The Euclidean distance is calculated between the testing data and the training data for each test sample.\n4. **K-Nearest Neighbors**: The script finds the nearest 10 neighbors for each test sample and performs classification based on the majority vote.\n5. **Accuracy Calculation**: The accuracy of the classifier is determined by comparing the predicted labels with the actual labels from the testing set.\n\n## Requirements:\n- Python 3.x\n- Pandas library\n- Math and Statistics libraries (both are standard Python libraries)\n\n## Files:\n- `Iris.csv`: Contains the Iris dataset with the following columns: Sepal Length, Sepal Width, Petal Length, Petal Width, and Class (label).\n  \n## How the Script Works:\n1. **Data Loading**: The dataset is read from `Iris.csv` using `pandas.read_csv()`.\n2. **Training and Testing Split**: The data is split into a random 100-point training set and the rest as a testing set.\n3. **Distance Calculation**: The script calculates the Euclidean distance between each test sample and all training samples.\n4. **Find Nearest Neighbors**: The nearest 10 neighbors for each test sample are identified.\n5. **Label Prediction**: The class label for each test sample is predicted based on the majority vote from its nearest neighbors.\n6. **Accuracy**: The percentage of correctly predicted labels is printed as the final result.\n\n## How to Run:\n1. Ensure you have Python installed along with the required libraries.\n2. Place the `Iris.csv` file in the same directory as the Python script.\n3. Run the script by executing `python knn_classifier.py` in the terminal.\n4. The script will output the accuracy of the classifier based on the K-Nearest Neighbors algorithm.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmahdikh03%2Fknn-algorithm-on-irisdataset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmahdikh03%2Fknn-algorithm-on-irisdataset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmahdikh03%2Fknn-algorithm-on-irisdataset/lists"}