Skip to content

This project implements the K-Nearest Neighbors (KNN) algorithm for classification purposes. KNN is a simple and effective algorithm for classifying data points based on their similarity to other data points in a given dataset.

Notifications You must be signed in to change notification settings

okdotdev/K-Nearest-Neighbors-Algorithm-Implementation-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

✨ KNN (K-Nearest Neighbors) Algorithm Implementation

This project implements the K-Nearest Neighbors (KNN) algorithm for classification purposes. KNN is a simple and effective algorithm for classifying data points based on their similarity to other data points in a given dataset. This project was made for NAI (Tools Of Artificial Inteligence) class at Pjait.

📝 Project Overview

The project consists of two main classes:

  1. KNN Class: This class encapsulates the logic for performing KNN classification. It includes methods for predicting tags, finding nearest neighbors, determining tags based on neighbors, calculating Euclidean distance, and displaying correct predictions percentage.

  2. Main Class: The main class contains the entry point of the application. It loads training and test data from files, prompts the user for the value of parameter k, performs classification on test data using the KNN model, and displays the percentage of correct predictions. Additionally, it allows users to input their own data for classification.

🚀 Usage

  1. Running the Application: Execute the Main.java file to start the application.
  2. Input: Provide the value of parameter k when prompted. The application will then classify test data using the KNN algorithm and display the percentage of correct predictions.
  3. Custom Input: After classification, the application allows users to input their own data for classification. Follow the prompts and input your data to see the predicted tag.

📁 Project Structure

  • KNN.java: Contains the implementation of the KNN algorithm.
  • Main.java: Entry point of the application, responsible for data loading, classification, and user interaction.
  • DataReader.java: Utility class for reading data from files.
  • Data.java: Class representing individual data instances.

🛠️ Dependencies

  • Java 8 or higher

About

This project implements the K-Nearest Neighbors (KNN) algorithm for classification purposes. KNN is a simple and effective algorithm for classifying data points based on their similarity to other data points in a given dataset.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages