Class PassiveAggressiveClassifier<T>
- Namespace
- AiDotNet.Classification.Linear
- Assembly
- AiDotNet.dll
Passive-Aggressive classifier for online learning.
public class PassiveAggressiveClassifier<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
TThe numeric data type used for calculations (e.g., float, double).
- Inheritance
-
PassiveAggressiveClassifier<T>
- Implements
-
IClassifier<T>
- Inherited Members
- Extension Methods
Remarks
The Passive-Aggressive algorithm is an online learning algorithm that: - Is "passive" when the prediction is correct (no update) - Is "aggressive" when wrong (makes the minimal update to correct the mistake)
For Beginners: Unlike regular gradient descent, Passive-Aggressive: 1. Only updates when it makes a mistake 2. When it updates, it does the minimum needed to fix the mistake
It's great for:
- Online learning (data arrives one sample at a time)
- Streaming data
- When you want a balance between learning and stability
The regularization parameter C controls the aggressiveness:
- Higher C: More aggressive updates (may overfit to noise)
- Lower C: More passive (may underfit)
Constructors
PassiveAggressiveClassifier(PassiveAggressiveOptions<T>?, IRegularization<T, Matrix<T>, Vector<T>>?)
Initializes a new instance of the PassiveAggressiveClassifier class.
public PassiveAggressiveClassifier(PassiveAggressiveOptions<T>? options = null, IRegularization<T, Matrix<T>, Vector<T>>? regularization = null)
Parameters
optionsPassiveAggressiveOptions<T>Configuration options for the classifier.
regularizationIRegularization<T, Matrix<T>, Vector<T>>Optional regularization strategy.
Properties
Options
Gets the PA classifier specific options.
protected PassiveAggressiveOptions<T> Options { get; }
Property Value
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.
GetModelMetadata()
Gets metadata about the model.
public override ModelMetadata<T> GetModelMetadata()
Returns
- ModelMetadata<T>
A ModelMetadata object containing information about the model.
Remarks
This method returns metadata about the model, including its type, feature count, complexity, description, and additional information specific to classification.
For Beginners: Model metadata provides information about the model itself, rather than the predictions it makes. This includes details about the model's structure (like how many features it uses) and characteristics (like how many classes it can predict). This information can be useful for understanding and comparing different models.
GetModelType()
Returns the model type identifier for this classifier.
protected override ModelType GetModelType()
Returns
Train(Matrix<T>, Vector<T>)
Trains the Passive-Aggressive classifier on the provided data.
public override void Train(Matrix<T> x, Vector<T> y)
Parameters
xMatrix<T>yVector<T>