MachineLearning/svm library

🧭 Support Vector Machine (linear SVM, primal hinge loss)

A compact linear SVM trained with subgradient descent on the primal hinge-loss objective. Returns weights [bias, w1, w2, ...] where the first element is the intercept term. Designed for clarity and small datasets; for large-scale problems prefer specialized libraries.

Contract:

  • Input: X as List<List<double>> (n x m), y as List<int> with labels {-1, +1}.
  • Output: List<double> of length m+1 representing bias followed by weights.

Time Complexity: O(epochs * n * m) Space Complexity: O(m)

Classes

SVMModel
Thin wrapper providing fit/predict interface for the linear SVM.

Functions

predictLinearSVM(List<double> model, List<double> x) → int
trainLinearSVM(List<List<double>> X, List<int> y, {double lr = 0.01, int epochs = 500, double C = 1.0}) → List<double>