Table of Contents

Class NuSupportVectorClassifier<T>

Namespace
AiDotNet.Classification.SVM
Assembly
AiDotNet.dll

Nu-Support Vector Classifier using the nu-SVM formulation.

public class NuSupportVectorClassifier<T> : SVMBase<T>, IProbabilisticClassifier<T>, IDecisionFunctionClassifier<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
NuSupportVectorClassifier<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

Nu-SVC uses a different parameterization than standard SVC. Instead of the C parameter, it uses nu which is an upper bound on the fraction of margin errors and a lower bound on the fraction of support vectors.

For Beginners: Nu-SVC is an alternative way to control the SVM's complexity:

Standard SVC uses C:

  • C controls the penalty for misclassification
  • Hard to interpret: "what does C=1.0 mean?"

Nu-SVC uses nu:

  • nu is between 0 and 1
  • nu is approximately the fraction of support vectors
  • nu is also an upper bound on training errors
  • More intuitive: "I want about 30% support vectors" means nu=0.3

Use Nu-SVC when:

  • You want more interpretable regularization
  • You have a target for the error rate
  • The C parameter in standard SVC is hard to tune

Note: Nu-SVC and standard SVC produce very similar results when properly tuned, but nu can be easier to set intuitively.

Constructors

NuSupportVectorClassifier(SVMOptions<T>?, IRegularization<T, Matrix<T>, Vector<T>>?, double)

Initializes a new instance of the NuSupportVectorClassifier class.

public NuSupportVectorClassifier(SVMOptions<T>? options = null, IRegularization<T, Matrix<T>, Vector<T>>? regularization = null, double nu = 0.5)

Parameters

options SVMOptions<T>

Configuration options for the Nu-SVC.

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

Optional regularization strategy.

nu double

The nu parameter (0 to 1). Default is 0.5.

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.

DecisionFunction(Matrix<T>)

Computes the decision function for the input samples.

public override Matrix<T> DecisionFunction(Matrix<T> input)

Parameters

input Matrix<T>

The input features matrix where each row is a sample.

Returns

Matrix<T>

A matrix of decision values. For binary classification, this is a single column representing the signed distance to the decision boundary. For multi-class, the shape depends on the multi-class strategy (OvR vs OvO).

Remarks

The decision function provides the "raw" output of the classifier before any probability calibration. For SVMs, this is the signed distance to the separating hyperplane.

For Beginners: This gives you the classifier's "confidence" without converting to probabilities.

Use this when you want to:

  • Apply custom thresholds for classification
  • Understand how confident the classifier is
  • Create your own probability calibration

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

ModelType

Predict(Matrix<T>)

Predicts class labels for the given input data by taking the argmax of probabilities.

public override Vector<T> Predict(Matrix<T> input)

Parameters

input Matrix<T>

The input features matrix where each row is an example and each column is a feature.

Returns

Vector<T>

A vector of predicted class indices for each input example.

Remarks

This implementation uses the argmax of the probability distribution to determine the predicted class. For binary classification with a custom decision threshold, you may want to use PredictProbabilities() directly and apply your own threshold.

For Beginners: This method picks the class with the highest probability for each sample.

For example, if the probabilities are [0.1, 0.7, 0.2] for classes [A, B, C], this method returns class B (index 1) because it has the highest probability (0.7).

PredictProbabilities(Matrix<T>)

Predicts class probabilities for each sample in the input.

public override Matrix<T> PredictProbabilities(Matrix<T> input)

Parameters

input Matrix<T>

The input features matrix where each row is a sample and each column is a feature.

Returns

Matrix<T>

A matrix where each row corresponds to an input sample and each column corresponds to a class. The values represent the probability of the sample belonging to each class.

Remarks

This abstract method must be implemented by derived classes to compute class probabilities. The output matrix should have shape [num_samples, num_classes], and each row should sum to 1.0.

For Beginners: This method computes the probability of each sample belonging to each class. Each row in the output represents one sample, and each column represents one class. The values in each row sum to 1.0 (100% total probability).

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

Trains the Nu-SVC on the provided data.

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

Parameters

x Matrix<T>
y Vector<T>