gizml:svm
support vector machines. The SMO solver of LIBSVM (second-order working set selection, Fan, Chen and Lin 2005) for C-SVC, nu-SVC, epsilon-SVR and nu-SVR, one-vs-one for more than two classes, and the dual coordinate descent of LIBLINEAR for linear SVC (squared hinge) and linear SVR (epsilon-insensitive). Matrices are row-major.
import * as Svm from "gizml:svm";Types
Kernel
type Kernel = { kind: string; gamma: f64; coef0: f64; degree: i64; }A kernel: rbf exp(-gamma |x - z|²), linear x·z, poly (gamma x·z + coef0)^degree, sigmoid tanh(gamma x·z + coef0).
kind:stringgamma:f64coef0:f64degree:i64
Svm
type Svm = { kernel: Kernel; features: i64; support: Vec<f64>; count: i64; coef: Vec<f64>; rho: Vec<f64>; classes: i64; }The support vectors (count × features), and for each decision function its coefficient of each support vector and its rho: f(x) = Σ coef K(sv, x) - rho. classes: 0 for regression (one function), else the class count (one function for each pair i < j, positive for class i).
kernel:M31.Kernelfeatures:i64support:Vec<f64>count:i64coef:Vec<f64>rho:Vec<f64>classes:i64
SvmParams
type SvmParams = { kernel: Kernel; cost: f64; nu: f64; epsilon: f64; tol: f64; maxIter: i64; }cost: C. nu: the nu of nu-SVC and nu-SVR (0 for the C variants). epsilon: the tube of epsilon-SVR. maxIter < 0: none.
kernel:M31.Kernelcost:f64nu:f64epsilon:f64tol:f64maxIter:i64
Functions
fitSvc
function fitSvc(x: Vec<f64>, n: i64, d: i64, y: Vec<f64>, k: i64, p: SvmParams): Svm throws stringSVC or nu-SVC on class indexes y (0..k-1): one-vs-one, the support vectors shared by the functions.
Effects: fail.
fitSvr
function fitSvr(x: Vec<f64>, n: i64, d: i64, y: Vec<f64>, p: SvmParams): Svmepsilon-SVR or nu-SVR on one target.
Effects: fail.
linearSvc
function linearSvc(x: Vec<f64>, n: i64, d: i64, y: Vec<f64>, cost: f64, tol: f64, maxIter: i64, rng: mut Random): Vec<f64>LIBLINEAR's dual coordinate descent with a bias feature of 1 (intercept_scaling 1), as scikit-learn's LinearSVC (squared hinge, one-vs-rest; y ±1) and LinearSVR (epsilon-insensitive). The weights: d values, then the intercept.
Effects: fail.
linearSvr
function linearSvr(x: Vec<f64>, n: i64, d: i64, y: Vec<f64>, cost: f64, epsilon: f64, tol: f64, maxIter: i64, rng: mut Random): Vec<f64>The weights and bias (last) of a linear support vector regression of the N × D matrix X onto Y, by dual coordinate descent with COST, EPSILON and TOL.
Effects: fail.
Methods
Svm.decisions
function Svm.decisions(self: Svm, row: Vec<f64>): Vec<f64>The decision values of one row: one for regression or two classes, one for each pair otherwise.
Effects: fail.
Svm.scores
function Svm.scores(self: Svm, row: Vec<f64>): Vec<f64>Regression: the prediction. Two classes: minus the decision value (positive for class 1, as scikit-learn's decision_function). More classes: the votes of each class, the lowest class winning a tie.
Effects: fail.