Table of Contents

Class SGDClassifier<T>

Namespace
AiDotNet.Classification.Linear
Assembly
AiDotNet.dll

Stochastic Gradient Descent classifier for large-scale learning.

public class SGDClassifier<T> : LinearClassifierBase<T>, IProbabilisticClassifier<T>, IClassifier<T>, IFullModel<T, Matrix<T>, Vector<T>>, IModel<Matrix<T>, Vector<T>, ModelMetadata<T>>, IModelSerializer, ICheckpointableModel, IParameterizable<T, Matrix<T>, Vector<T>>, IFeatureAware, IFeatureImportance<T>, ICloneable<IFullModel<T, Matrix<T>, Vector<T>>>, IGradientComputable<T, Matrix<T>, Vector<T>>, IJitCompilable<T>

Type Parameters

T

The numeric data type used for calculations (e.g., float, double).

Inheritance
SGDClassifier<T>
Implements
IFullModel<T, Matrix<T>, Vector<T>>
IModel<Matrix<T>, Vector<T>, ModelMetadata<T>>
IParameterizable<T, Matrix<T>, Vector<T>>
ICloneable<IFullModel<T, Matrix<T>, Vector<T>>>
IGradientComputable<T, Matrix<T>, Vector<T>>
Inherited Members
Extension Methods

Remarks

SGD is an optimization technique that updates weights using one sample at a time. This makes it very efficient for large datasets that don't fit in memory.

For Beginners: Instead of computing gradients over the entire dataset, SGD: 1. Picks one training sample 2. Computes how wrong the prediction is 3. Updates weights to reduce that error 4. Repeats for all samples (one epoch) 5. Repeats for multiple epochs

Benefits:

  • Very fast for large datasets
  • Can handle streaming data
  • Often finds good solutions quickly

Trade-offs:

  • Noisy updates (not always improving)
  • Requires tuning learning rate
  • May oscillate near optimal solution

Constructors

SGDClassifier(LinearClassifierOptions<T>?, IRegularization<T, Matrix<T>, Vector<T>>?)

Initializes a new instance of the SGDClassifier class.

public SGDClassifier(LinearClassifierOptions<T>? options = null, IRegularization<T, Matrix<T>, Vector<T>>? regularization = null)

Parameters

options LinearClassifierOptions<T>

Configuration options for the classifier.

regularization IRegularization<T, Matrix<T>, Vector<T>>

Optional regularization strategy.

Methods

Clone()

Creates a clone of the classifier model.

public override IFullModel<T, Matrix<T>, Vector<T>> Clone()

Returns

IFullModel<T, Matrix<T>, Vector<T>>

A new instance of the model with the same parameters and options.

CreateNewInstance()

Creates a new instance of the same type as this classifier.

protected override IFullModel<T, Matrix<T>, Vector<T>> CreateNewInstance()

Returns

IFullModel<T, Matrix<T>, Vector<T>>

A new instance of the same classifier type.

GetModelType()

Returns the model type identifier for this classifier.

protected override ModelType GetModelType()

Returns

ModelType

Train(Matrix<T>, Vector<T>)

Trains the SGD classifier on the provided data.

public override void Train(Matrix<T> x, Vector<T> y)

Parameters

x Matrix<T>
y Vector<T>