OnlineSGDClassifier<T>
Models & Types · AiDotNet.OnlineLearning
Online Stochastic Gradient Descent classifier for incremental learning.
Inheritance: OnlineLearningModelBase<T> → OnlineSGDClassifier<T>
For Beginners
This classifier learns to separate two classes using a linear decision boundary, updating itself one example at a time.
How it works:
- Compute prediction: P(y=1) = sigmoid(w·x + b)
- Compare with true label: error = prediction - truth
- Update weights: w = w - learning_rate × error × x
The model “nudges” itself toward correct predictions with each example. Over many examples, it converges to a good decision boundary.
Advantages:
- Handles streaming data naturally
- Memory-efficient (doesn’t store data)
- Can adapt to changing patterns
Supports:
- L1 regularization (sparse weights)
- L2 regularization (smooth weights)
- Elastic Net (combination)
Usage:
References:
- Bottou, L. (2010). “Large-Scale Machine Learning with Stochastic Gradient Descent”
How It Works
Online SGD Classifier implements logistic regression with SGD updates, allowing the model to learn incrementally from streaming data.
Constructors
| Constructor | Summary |
|---|---|
OnlineSGDClassifier(double learningRate, LearningRateSchedule learningRateSchedule, double l1Penalty, double l2Penalty, bool fitIntercept) |
Gets the model type. |
Methods
| Method | Summary |
|---|---|
Dictionary<string, T> GetFeatureImportance() |
Gets the feature importance scores (absolute weights). |
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters) |
Creates a new instance with specified parameters. |
T DecisionFunction(Vector<T> x) |
Computes the score used for decision (before sigmoid). |
T GetBias() |
Gets the bias (intercept) term. |
T PredictProbability(Vector<T> x) |
Predicts the probability of class 1. |
T PredictSingle(Vector<T> x) |
Predicts the target value for a single sample. |
Vector<T> GetWeights() |
Gets the weights vector. |
Vector<T> PredictProbabilities(Matrix<T> x) |
Predicts probabilities for all samples. |
void PartialFit(Vector<T> x, T y) |
Updates the model with a single training example. |
void Reset() |
Resets the model to its initial state. |