Module rusty_machine::learning::svm [] [src]

Support Vector Machine Module

Contains implementation of Support Vector Machine using the Pegasos training algorithm.

The SVM models currently only support binary classification. The model inputs should be a matrix and the training targets are in the form of a vector of -1s and 1s.

Examples

use rusty_machine::learning::svm::SVM;
use rusty_machine::learning::SupModel;

use rusty_machine::linalg::Matrix;
use rusty_machine::linalg::Vector;

let inputs = Matrix::new(4,1,vec![1.0,3.0,5.0,7.0]);
let targets = Vector::new(vec![-1.,-1.,1.,1.]);

let mut svm_mod = SVM::default();

// Train the model
svm_mod.train(&inputs, &targets).unwrap();

// Now we'll predict a new point
let new_point = Matrix::new(1,1,vec![10.]);
let output = svm_mod.predict(&new_point).unwrap();

// Hopefully we classified our new point correctly!
assert!(output[0] == 1f64, "Our classifier isn't very good!");

Structs

SVM

Support Vector Machine