SupportVectorClassifier<T>

Models & Types · AiDotNet.Classification.SVM

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

Inheritance: ClassifierBase<T> → ProbabilisticClassifierBase<T> → SVMBase<T> → SupportVectorClassifier<T>

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

How It Works

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

Example

var labels = new Vector<double>(new double[] { 0.0, 1.0, 0.0, 1.0 });
var newSample = new Matrix<double>(new double[,] { { 1.0, 2.0 }, { 3.0, 4.0 }, { 5.0, 6.0 }, { 7.0, 8.0 } });
var features = new Matrix<double>(new double[,] { { 1.0, 2.0 }, { 3.0, 4.0 }, { 5.0, 6.0 }, { 7.0, 8.0 } });
// Use AiModelBuilder facade for supportvectorclassifier classification
var builder = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
    .ConfigureModel(new SupportVectorClassifier<double>(
        new SVMOptions<double>()));
            
var result = builder.Build(features, labels);
var prediction = result.Predict(newSample);

Constructors

Constructor Summary
SupportVectorClassifier(SVMOptions<T> options, IRegularization<T, Matrix<T>, Vector<T>> regularization) Initializes a new instance of the SupportVectorClassifier class.

Methods

Method Summary
Matrix<T> DecisionFunction(Matrix<T> input)
Matrix<T> PredictProbabilities(Matrix<T> input)
void Train(Matrix<T> x, Vector<T> y) Returns the model type identifier for this classifier.