sklears-svm
High-performance Support Vector Machine implementations for Rust with advanced kernels and optimization algorithms, delivering 5-15x speedup over scikit-learn.
Latest release:
0.2.0(July 14, 2026). See the workspace release notes for highlights and upgrade guidance.
Overview
sklears-svm provides comprehensive SVM implementations:
- Core Algorithms: SVC, SVR, LinearSVC, NuSVC, NuSVR, SparseSVM
- Kernel Functions: Linear, RBF, Polynomial, Sigmoid, Cosine, Chi-Squared, Intersection, custom
Kerneltrait implementations - Optimization: SMO, coordinate descent, stochastic gradient descent
- Advanced Features: Multi-class strategies (One-vs-Rest, One-vs-One, ECOC, hierarchical), probability calibration (Platt scaling, isotonic), online/incremental learning
- Performance: SIMD optimization, sparse data support, optional CUDA acceleration via
oxicuda-blas(feature-gated)
Quick Start
use ;
use ;
use array;
// Classification with RBF kernel
let svc = SVCnew
.rbf
.c
.probability;
// Regression with polynomial kernel
let svr = SVRnew
.poly
.epsilon;
// Linear SVM for large-scale problems
let linear_svc = new
.with_penalty
.with_loss
.with_dual; // Primal optimization for n_samples >> n_features
// Train and predict
let x = array!;
let y = array!;
let fitted = svc.fit?;
let predictions = fitted.predict?;
let probabilities = fitted.predict_proba?;
Advanced Features
Custom Kernels
Implement the Kernel trait for a custom kernel function, or select any of the
built-in kernels through KernelType:
use ;
use ArrayView1;
use HashMap;
// Built-in kernels are selected through `KernelType`
let svc = SVCnew.kernel.c;
Multi-class Strategies
use ;
// One-vs-Rest strategy (default)
let svc_ovr = new.strategy;
// One-vs-One strategy with majority voting
let svc_ovo = new.strategy;
// Error-Correcting Output Codes
let svc_ecoc = new.strategy;
Online Learning
use ;
let mut online_svm = new;
// Incremental learning, one sample at a time
for in data_stream
Probability Calibration
use SVC;
let svc = SVCnew.rbf.probability; // fits Platt scaling internally
let fitted = svc.fit?;
let calibrated_probs = fitted.predict_proba?;
Performance Features
Sparse Data Support
use SparseSVM;
let sparse_svc = new
.with_c
.with_loss;
let fitted = sparse_svc.fit?; // y: Array1<i32> class labels
Parallel Training
Enable the parallel feature (on by default) to parallelize kernel-matrix and
gradient computations internally via rayon. Kernel-cache size is tunable per
estimator:
let svc = SVCnew
.rbf
.cache_size; // MB for kernel cache
Optimization Strategies
use ;
// SMO with shrinking heuristics (SVC's built-in solver)
let svc_smo = SVCnew.rbf.shrinking;
// Coordinate descent for linear SVM ('dual_cd', 'primal_cd', 'enhanced_cd')
let linear_svc_cd = new.with_solver;
// Stochastic gradient descent
let sgd_svm = new.with_alpha.with_max_iter;
Advanced Algorithms
Nu-Support Vector Machines
use ;
// Nu-SVC with automatic margin
let nu_svc = new
.nu? // Upper bound on fraction of margin errors
.kernel;
// Nu-SVR for regression
let nu_svr = new
.nu?
.kernel;
Benchmarks
Performance comparisons:
| Algorithm | scikit-learn | sklears-svm | Speedup |
|---|---|---|---|
| Linear SVC | 45ms | 5ms | 9x |
| RBF SVC | 120ms | 15ms | 8x |
| Nu-SVC | 135ms | 18ms | 7.5x |
| SGD Classifier | 8ms | 0.8ms | 10x |
Architecture
sklears-svm/
├── core/ # Core SVM algorithms
├── kernels/ # Kernel implementations
├── solvers/ # Optimization algorithms
├── multiclass/ # Multi-class strategies
├── online/ # Incremental learning
├── sparse/ # Sparse data support
└── gpu/ # GPU acceleration (feature-gated, oxicuda-blas)
Status
- Tests: 302 passing crate tests for
0.2.0(38 skipped) - Core Algorithms: 90% complete
- Kernel Functions: All major kernels implemented
- Optimization: SMO, CD, SGD implemented
- GPU Support: Implemented behind the
gpufeature —oxicuda-blasGEMM drives the inner-product term for Linear/RBF/Polynomial/Sigmoid kernels, with the RBF/Sigmoid non-linear transform also running on-device
Contributing
Priority areas for contribution:
- Additional kernel functions
- Performance optimizations
- Cross-validation utilities
See CONTRIBUTING.md for guidelines.
License
Licensed under the Apache License, Version 2.0.
Citation