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.
The project consists of two main classes:
-
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.
-
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.
- Running the Application: Execute the
Main.java
file to start the application. - 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.
- 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.
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.
- Java 8 or higher