This is a simple Java implementation of a Perceptron binary classifier trained to distinguish between two Iris species: Iris-versicolor and Iris-virginica. It reads training and test data from CSV files and allows users to evaluate accuracy or classify custom vectors.
- A
Parceptronclass handles training, weight updates, and predictions using the perceptron learning algorithm. - The
Mainclass:- Loads data from CSV files.
- Trains the perceptron.
- Provides a CLI menu to evaluate accuracy or classify a user-defined vector.
Each line in the CSV should be:
sepal_length,sepal_width,petal_length,petal_width,class_label
- Last column must be either
Iris-versicolororIris-virginica.
Example:
6.3,2.8,5.1,1.5,Iris-virginica
5.7,2.8,4.1,1.3,Iris-versicolor
- Compile the code:
javac Main.java Parceptron.java- Run with training and test files:
java Main iris_train.csv iris_test.csv- CLI Options:
0β Show accuracy on test set1β Manually classify a new vector2β Exit program
After selecting 1 in the CLI:
Type vector's dimension:
4
Type coordinate:
6.1
Type coordinate:
2.9
Type coordinate:
4.7
Type coordinate:
1.4
Vector is classified to class Iris-versicolor
- The perceptron uses a fixed learning rate (0.01) and number of epochs (500).
- Bias and weights are initialized randomly.
- File path must be relative to
src/directory.
Enjoy experimenting with machine learning in Java!