PerceptronClassifier<T>
Models & Types · AiDotNet.Classification.Linear
Classic Perceptron classifier - the original neural network building block.
Inheritance: ClassifierBase<T> → ProbabilisticClassifierBase<T> → LinearClassifierBase<T> → PerceptronClassifier<T>
For Beginners
The Perceptron is the simplest possible neural network:
How it works:
- Start with zero weights
- For each training sample:
- If correct: do nothing
- If wrong: adjust weights in the direction of the correct class
- Repeat until no mistakes (or max iterations)
Properties:
- Only works for linearly separable data
- Guaranteed to converge if data IS linearly separable
- Never converges if data is NOT linearly separable
- No notion of margin (unlike SVM)
Historical note: The Perceptron was invented in 1958 by Frank Rosenblatt and was one of the first machine learning algorithms ever created!
How It Works
The Perceptron is a linear classifier that updates weights only on mistakes. It’s historically significant as the foundation of neural networks.
Example
// Create the classic Perceptron classifier
var options = new LinearClassifierOptions<double>();
// Prepare linearly separable training data: 6 samples with 2 features
var features = new Matrix<double>(6, 2);
features[0, 0] = 1.0; features[0, 1] = 1.1;
features[1, 0] = 1.2; features[1, 1] = 0.9;
features[2, 0] = 0.8; features[2, 1] = 1.0;
features[3, 0] = 5.0; features[3, 1] = 5.1;
features[4, 0] = 5.2; features[4, 1] = 4.9;
features[5, 0] = 4.8; features[5, 1] = 5.0;
var labels = new Vector<double>(new double[] { 0, 0, 0, 1, 1, 1 });
// Train by updating weights only on misclassified samples
var result = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
.ConfigureModel(new PerceptronClassifier<double>(options))
.Build(features, labels);
// Predict using learned linear boundary
var newSample = new Matrix<double>(1, 2);
newSample[0, 0] = 1.1; newSample[0, 1] = 1.0;
var prediction = result.Predict(newSample);
// Result is available in the returned value
Constructors
| Constructor | Summary |
|---|---|
PerceptronClassifier(LinearClassifierOptions<T> options, IRegularization<T, Matrix<T>, Vector<T>> regularization) |
Initializes a new instance of the PerceptronClassifier class. |
Methods
| Method | Summary |
|---|---|
void Train(Matrix<T> x, Vector<T> y) |
Returns the model type identifier for this classifier. |