Skip to main content

Module svm

Module svm 

Source
Expand description

A linear SVM: L2-regularized, squared hinge loss, solved in the dual by coordinate descent with shrinking (Hsieh, Chang, Lin, Keerthi & Sundararajan, “A dual coordinate descent method for large-scale linear SVM”, ICML 2008: liblinear’s solver for -s 1).

The primal it solves, with x̃ = (x, bias) and w̃ = (w, w_b): min ½‖w̃‖² + Σ Cᵢ max(0, 1 − yᵢ w̃·x̃ᵢ)², where Cᵢ is C times the weight of the message’s class (ham weighs more: calling ham spam costs more). The bias is a feature of its own and is regularized, as liblinear’s -B. Rows are dense f32 (the standardized message vector and header features); every sum is f64.

Structs§

Cancelled
Learning was stopped from outside.
Model
A learned linear SVM: decision(x) = w·x + b, positive for spam.
Params
How the SVM learns.
Problem
The rows to learn from.

Constants§

HAM
SPAM
Labels: spam is +1, ham −1.

Functions§

dot 🔒
train
Learns problem’s SVM. cancelled is asked once per pass.