Skip to content

About

KNN ML model to detect Engine Failure written in C++

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

Engine Failure Detection using K-Nearest Neighbors (C++)

This project implements a KNN algorithm from scratch in C++ to detect and classify engine failures based on sensor data. It includes data preprocessing, normalisation, and a distance-weighted voting mechanism to evaluate predictive accuracy.

Dataset

The data used for this project is the Engine Failure Detection Dataset available on Kaggle.

Important Data Preprocessing Note: Before running the program, the timestamp column was manually removed from the downloaded CSV file.

Features

  • Custom KNN Implementation: No external machine learning libraries are used. The algorithm calculates the Euclidean distance between data points.
  • Distance-Weighted Voting: Rather than a simple majority vote, the algorithm gives closer neighbours a higher influence on the final prediction, improving accuracy.
  • Automatic Normalisation: Features with vastly different scales (like RPM in the thousands vs. Fuel Efficiency in the tens) are automatically normalised so they contribute equally to the distance calculation.
  • Configurable Hyperparameters: Easily adjust the k value, training/testing split ratio, and seed for shuffling directly at the top of the source file.

Project Structure

Ensure your dataset is placed correctly within the data folder before running the code so that the relative file paths resolve correctly:

├── CMakeLists.txt          # CMake configuration file
├── CMakePresets.json       # CMake build and configuration presets
├── EngineFailureKNN.cpp    # The main C++ source code for the KNN algorithm
├── LICENSE.txt             # License information
├── README.md               # Project documentation
├── data/                   # Directory containing the dataset
│   └── engine_failure_dataset.csv 
└── out/                    # Build output directory (generated by CMake/your IDE)

Configuration

You can tweak the behavior of the model by modifying the global variables at the top of the main.cpp file:

  • DATA_FILE: Path to your dataset (default is "data/engine_failure_dataset.csv").
  • Train_Split: The ratio of data used for training vs testing (default 0.7 for a 70/30 split).
  • k: The number of nearest neighbors to check.

How to Build and Run

This project uses CMake for its build system.

  1. Open a terminal or command prompt in the project's root directory.
  2. Create a build directory and navigate into it:
mkdir build
cd build
  1. Generate the build files using CMake:
cmake ..
  1. Compile the project:
cmake --build .
  1. Run the compiled executable:
# On Linux/macOS
./EngineFailureKNN

# On Windows
Debug\EngineFailureKNN.exe

Notes

This project was purely to learn C++ syntax so the focus wasn't squeezing performance. It averages 70-75% accuracy.

About

KNN ML model to detect Engine Failure written in C++

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages