Table of Contents

Class SupportVectorClassifier<T>

Namespace
AiDotNet.Classification.SVM
Assembly
AiDotNet.dll

Support Vector Classifier using kernel methods for non-linear classification.

public class SupportVectorClassifier<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
SupportVectorClassifier<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

This implementation uses a simplified Sequential Minimal Optimization (SMO) algorithm to find the optimal separating hyperplane in the kernel-induced feature space.

For Beginners: The Support Vector Classifier (SVC) finds the best boundary between classes by:

  1. Looking at all training points
  2. Finding the points closest to the decision boundary (support vectors)
  3. Drawing a boundary that maximizes the margin to these support vectors
  4. Using a kernel trick to handle non-linear boundaries

Common use cases:

  • Text classification (spam detection, sentiment analysis)
  • Image classification
  • Bioinformatics (protein classification)
  • Any problem with clear separation between classes

Constructors

SupportVectorClassifier(SVMOptions<T>?, IRegularization<T, Matrix<T>, Vector<T>>?)

Initializes a new instance of the SupportVectorClassifier class.

public SupportVectorClassifier(SVMOptions<T>? options = null, IRegularization<T, Matrix<T>, Vector<T>>? regularization = null)

Parameters

options SVMOptions<T>

Configuration options for the SVC.

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.

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

GetModelType()

Returns the model type identifier for this classifier.

protected override ModelType GetModelType()

Returns

ModelType

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 SVC on the provided data.

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

Parameters

x Matrix<T>
y Vector<T>