{"id":21584936,"url":"https://github.com/abshar-shihab/fruit_prediction_using_knn_classification_model","last_synced_at":"2025-07-21T21:37:30.073Z","repository":{"id":263990943,"uuid":"892013384","full_name":"Abshar-Shihab/Fruit_prediction_using_KNN_Classification_model","owner":"Abshar-Shihab","description":"This repository contains a Python implementation of the K-Nearest Neighbors (KNN) algorithm for predicting the class of fruits based on features such as size, weight, and colour.","archived":false,"fork":false,"pushed_at":"2024-11-21T11:22:58.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T09:13:08.445Z","etag":null,"topics":["knn-algorithm","knn-classification","machine-learning","prediction","prediction-model"],"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/Abshar-Shihab.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-11-21T11:08:12.000Z","updated_at":"2024-11-21T11:27:55.000Z","dependencies_parsed_at":"2024-11-21T17:00:42.577Z","dependency_job_id":null,"html_url":"https://github.com/Abshar-Shihab/Fruit_prediction_using_KNN_Classification_model","commit_stats":null,"previous_names":["abshar-shihab/fruit_prediction_using_knn_classification_model"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Abshar-Shihab/Fruit_prediction_using_KNN_Classification_model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abshar-Shihab%2FFruit_prediction_using_KNN_Classification_model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abshar-Shihab%2FFruit_prediction_using_KNN_Classification_model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abshar-Shihab%2FFruit_prediction_using_KNN_Classification_model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abshar-Shihab%2FFruit_prediction_using_KNN_Classification_model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Abshar-Shihab","download_url":"https://codeload.github.com/Abshar-Shihab/Fruit_prediction_using_KNN_Classification_model/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abshar-Shihab%2FFruit_prediction_using_KNN_Classification_model/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266384515,"owners_count":23921067,"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","status":"online","status_checked_at":"2025-07-21T11:47:31.412Z","response_time":64,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["knn-algorithm","knn-classification","machine-learning","prediction","prediction-model"],"created_at":"2024-11-24T15:08:31.188Z","updated_at":"2025-07-21T21:37:30.035Z","avatar_url":"https://github.com/Abshar-Shihab.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fruit_prediction_using_KNN_Classification_model\nThis repository contains a Python implementation of the K-Nearest Neighbors (KNN) algorithm for predicting the class of fruits based on features such as size, weight, and colour.\n\n\n---\n\n## Description: Fruit Prediction using K-Nearest Neighbors (KNN)\n\nThis repository contains a Python implementation of the K-Nearest Neighbors (KNN) algorithm for predicting the class of fruits based on features such as size, weight, and color. The KNN algorithm is a simple, non-parametric supervised learning method that classifies data points based on the majority class of their nearest neighbors in the feature space.\n\n### Features\n- **KNN Classifier:** Implements the core KNN logic, including calculating distances, finding neighbors, and predicting classes.\n- **Euclidean Distance Metric:** Measures the similarity between data points.\n- **CSV File Support:** Reads fruit data from a CSV file and uses it for training and testing the model.\n- **Dynamic K-Value:** Allows selection of the number of nearest neighbors (K) to tune classification performance.\n\n### Dataset\nThe dataset consists of fruit characteristics:\n- **Features:** Mass, width, height, color_score\n- **Labels:** Class of fruit (1, 2, 3, 4)\n\n---\n\n\n## Usage\n\n1. Place your dataset in the same directory as the script and name it `fruit_data_with_colours.csv`.\n\n2. Run the script:\n   ```bash\n   python knn_fruit_prediction.py\n   ```\n\n3. Modify the number of neighbors (K) in the script to observe how it affects the predictions.\n\n---\n\n## Steps in KNN\n\n### Step 1: Distance Calculation\n- The Euclidean distance is used to measure similarity between data points:\n  \\[\n  \\text{Distance} = \\sqrt{\\sum_{i=1}^n (x_i - y_i)^2}\n  \\]\n\n### Step 2: Finding K Nearest Neighbors\n- Distances between the test point and all training points are calculated and sorted.\n- The K points with the smallest distances are selected as the neighbors.\n\n### Step 3: Predicting the Class\n- The most common class among the neighbors is assigned to the test data.\n\n---\n\n## Dataset\n\nThe dataset should be in CSV format, with the following structure:\n\n| fruit_label | Mass | Width  | height      | color_score |\n|-------------|------|--------|-------------|--------|\n|      1      | 192  | 8.4    | 7.3         | 0.55   |\n|      2      | 86   | 6.2    | 4.7         | 0.77   |\n|    ...      | ...  | ...    | ...         | ...    |\n\nReplace `fruit_data_with_colours.csv` with your own dataset if needed.\n\n\n\n## Contributing\n\nContributions are welcome! Feel free to submit issues or pull requests.\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabshar-shihab%2Ffruit_prediction_using_knn_classification_model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabshar-shihab%2Ffruit_prediction_using_knn_classification_model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabshar-shihab%2Ffruit_prediction_using_knn_classification_model/lists"}