This project implements a basic classification algorithm using a perceptron model created from scratch, in order to classify objects found in a SONAR dataset, into Mines & Rocks.
- Initialize the weights and threshold to small random numbers.
- Present a vector X to the neuron inputs and calculate the output
- Update the weights according to:
where
weights[i+1] = weights[i+1] + learning_rate * error * row[i]
iis the iteration number, andlearning_rateis the gain or step size, where0.0 < n < 1.0
- Repeat 2 & 3 until:
- The iteration is less than a user-specified error threshold or
- The predetermined number of iterations have been completed
('M' denotes Mine, 'R' denotes Rock)
Output of the Perceptron Algorithm for the SONAR dataset with the following values
- Folds : 2
- Initial Learning Rate : 0.01
- Epochs : 400
The output here is taken with the same values for folds, learning_rate and number_of_epochs but the accuracy varies beacuse the Cross-Validation technique makes folds at random.
{'M':0, 'R':1}
Scores : [83.65384615384616, 69.23076923076923]
Mean Accuracy : 76.442 %
Scores : [72.11538461538461, 68.26923076923077]
Mean Accuracy : 70.192 %
Scores : [70.1923076923077, 74.03846153846155]
Mean Accuracy : 72.115 %Thanks to the code provided by Matthew Carter. The code used as reference for the project is available here.