Skip to content

A perceptron classifier for the Iris dataset implemented entirely from scratch in C++. Includes manual CSV parsing, handcrafted train/test splitting, basic weight initialization, explicit perceptron learning rule, and accuracy evaluation without external ML libraries.

License

Notifications You must be signed in to change notification settings

kacper673/Preceptron-classifier-from-scratch

Repository files navigation

Perceptron Iris Classifier - From Scratch

This project demonstrates how a perceptron - one of the simplest neural models - can be built entirely from scratch in C++.
No machine learning libraries, no high-level frameworks: just basic data structures, loops, and arithmetic.

The program classifies samples from the Iris dataset into two categories by directly implementing:

  • manual dataset parsing,
  • handcrafted train/test splitting,
  • weight initialization with basic random numbers,
  • perceptron learning rule with explicit updates,
  • accuracy evaluation without external tools.

  • Raw Data Handling

    • CSV parsing implemented line by line using streams.
    • Features stored in a simple Input struct with std::vector<double> for attributes and an integer label.
  • Perceptron from First Principles

    • Weights are just a std::vector<double>.
    • Predictions use a dot product + bias.
    • Error drives updates according to the original Rosenblatt learning rule.
  • Train/Test Split Without Libraries

    • Random shuffling and slicing of vectors.
    • Implemented directly with STL algorithms (std::shuffle) instead of scikit-learn–style utilities.
  • Accuracy Check

    • Counting correct predictions with explicit loops.
    • No metrics libraries - only integer counters and division.
  • Visualisation of Learning

    • Saving necessary data to csv
    • Python script to process and plot the data
    • Plotting in Matplotlib

📸 Example Screenshots

  • Charts plotted with Matplotlib showig impoving accuracy over each epoch

    Zrzut ekranu 2025-09-19 233309

Zrzut ekranu 2025-09-19 233224
  • Accuracy after every epoch and final accuracy of the model
image
  • Learning process info (debug flag = true)
image
  • Adjusting learning paramters (eta, epochs) influences the model performacne, for example small eta makes model perform very poorly despite relativly many epochs
image

About

A perceptron classifier for the Iris dataset implemented entirely from scratch in C++. Includes manual CSV parsing, handcrafted train/test splitting, basic weight initialization, explicit perceptron learning rule, and accuracy evaluation without external ML libraries.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages