Skip to main content

anofox_ml_svm/
lib.rs

1//! # anofox-ml SVM
2//!
3//! Support Vector Machine classifiers for the anofox-ml machine learning library.
4//!
5//! This crate provides two SVM classifiers:
6//!
7//! - [`LinearSvc`] -- Linear Support Vector Classifier using hinge loss + L2
8//!   regularization, solved via coordinate descent (similar to sklearn's
9//!   `LinearSVC` with liblinear).
10//! - [`Svc`] -- Support Vector Classifier with kernel support (linear, RBF,
11//!   polynomial), solved via a simplified SMO algorithm.
12//!
13//! Both classifiers support binary and multi-class classification (via
14//! one-vs-rest strategy).
15//!
16//! ## Example
17//!
18//! ```rust
19//! use anofox_ml_core::{Fit, Predict};
20//! use anofox_ml_svm::{LinearSvc, Svc, SvmKernel};
21//! use ndarray::array;
22//!
23//! // Linear SVC
24//! let x = array![[0.0, 0.0], [0.1, 0.1], [5.0, 5.0], [5.1, 5.1]];
25//! let y = array![0.0, 0.0, 1.0, 1.0];
26//!
27//! let svc = LinearSvc::new().with_c(1.0);
28//! let model = svc.fit(&x, &y).unwrap();
29//! let preds = model.predict(&x).unwrap();
30//!
31//! // Kernel SVC with RBF
32//! let svc = Svc::new()
33//!     .with_kernel(SvmKernel::Rbf { gamma: 0.5 })
34//!     .with_c(10.0);
35//! let model = svc.fit(&x, &y).unwrap();
36//! let preds = model.predict(&x).unwrap();
37//! ```
38
39mod kernel;
40mod linear_svc;
41mod linear_svr;
42mod nu_svc;
43mod nu_svr;
44mod one_class_svm;
45mod svc;
46mod svr;
47
48pub use kernel::SvmKernel;
49pub use linear_svc::{FittedLinearSvc, LinearSvc};
50pub use linear_svr::{FittedLinearSvr, LinearSvr};
51pub use nu_svc::{FittedNuSvc, NuSvc};
52pub use nu_svr::{FittedNuSvr, NuSvr};
53pub use one_class_svm::{FittedOneClassSvm, OneClassSvm};
54pub use svc::{FittedSvc, Svc};
55pub use svr::{FittedSvr, Svr};