OnlineSGDRegressor<T>

Models & Types · AiDotNet.OnlineLearning

Online Stochastic Gradient Descent regressor for incremental learning.

Inheritance: OnlineLearningModelBase<T> → OnlineSGDRegressor<T>

For Beginners

This regressor predicts continuous values using a linear model, updating itself one example at a time.

How it works:

  1. Compute prediction: ŷ = w·x + b
  2. Compare with true value: error = prediction - truth
  3. Update weights: w = w - learning_rate × error × x

Over many examples, the model converges to the best linear fit.

Supports multiple loss functions:

  • Squared error (default): Sensitive to outliers
  • Huber loss: Robust to outliers
  • Epsilon-insensitive: SVR-like, ignores errors smaller than epsilon

Usage:

References:

  • Bottou, L. (2010). “Large-Scale Machine Learning with Stochastic Gradient Descent”

How It Works

Online SGD Regressor implements linear regression with SGD updates, allowing the model to learn incrementally from streaming data.

Constructors

Constructor Summary
OnlineSGDRegressor(double learningRate, LearningRateSchedule learningRateSchedule, double l1Penalty, double l2Penalty, bool fitIntercept, SGDLossType loss, double epsilon) 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 GetBias() Gets the bias (intercept) term.
T PredictSingle(Vector<T> x) Predicts the target value for a single sample.
T Score(Matrix<T> x, Vector<T> y) Gets the R-squared score on the provided data.
Vector<T> GetWeights() Gets the weights vector.
void PartialFit(Vector<T> x, T y) Updates the model with a single training example.
void Reset() Resets the model to its initial state.
void Train(Matrix<T> x, Vector<T> y) Batch training over the full dataset, following scikit-learn SGDRegressor.fit: run multiple epochs (up to max_iter) of single-pass SGD, stopping early once the mean training loss stops improving by more than tol for n_iter_no_change…