optimized-svm
➜ Interactive demos, benchmarks and a summary of the thesis on the project website · Documentation
Support vector machines whose hyperparameters are tuned by exact gradients instead of grid search.
optimized-svm treats hyperparameter selection as a bilevel optimization problem: the upper level
minimizes a (smoothed) cross-validation error, the lower level is the SVM training problem. Smoothing
the loss makes the training solution differentiable in the hyperparameters, so the gradient of the
CV error follows from the implicit function theorem and a quasi-Newton method (L-BFGS-B) can be used.
This works for the regularization parameter and for per-feature kernel scalings (automatic
relevance determination), where grid search is hopeless.
The methods are developed in
N. Strasdat, Duality, Derivative-Based Training Methods and Hyperparameter Optimization for Support Vector Machines, Dissertation, Technische Universität Dresden, 2023. urn:nbn🇩🇪bsz:14-qucosa2-874731
Training uses the Rust SMO solver smo-solver as a warm start
followed by a semismooth Newton method on the smoothed primal problem.
Features
- scikit-learn estimators:
OptimizedSVC,OptimizedSVR(tuned) andSmoothSVC,SmoothSVR(fixed hyperparameters); binary and one-vs-rest classification - losses: smoothed hinge, logistic (with
predict_proba), smoothed ε-insensitive, squared (LS-SVM), Poisson; smoothing of degree 2, 3 or 6; sample/class weights; optional bound onΣ|α|(generalized ν-SVM) - exact hypergradients via one adjoint linear system per fold (verified against finite differences), also with respect to the loss parameters ε and δ (low-level API)
- ARD kernels (
blocks="features") with two-stage optimization, warm starts, time limits, full optimization history decision_gradient()for local feature sensitivities- kernel GLMs:
KernelGLMRegressor,OptimizedKernelGLMRegressorwith Poisson, binomial (trials), negative binomial (dispersion tuned by the hypergradient), Gamma and Tweedie families, offsets/exposure and a D² score - scikit-learn CV splitters with
groups(e.g.LeaveOneGroupOut) - multi-class soft-max model (
multi_class="softmax", one joint model with common hyperparameters) - parallel cross-validation folds (
n_jobs)
Hard constraints from thesis Sec. 4.1.2/4.2.3 are also available as loss="hard_margin" and
loss="hard_epsilon_insensitive" (0.6.0): direct constrained training and local active-set
hypergradients. See the guide and example.
Installation
pip install optimized-svm
For development (the solver smo-solver is installed
from PyPI as a prebuilt wheel):
git clone https://github.com/wotzlaff/optimized-svm && cd optimized-svm
uv sync --group dev
uv run pytest
Quick start
from sklearn.datasets import make_friedman1
from optimized_svm import OptimizedSVR
x, y = make_friedman1(600, noise=0.5, random_state=0)
model = OptimizedSVR(blocks="features").fit(x, y) # one kernel scaling per feature
model.lam_ # optimized regularization parameter
model.scaling_opt_ # optimized scalings: features 5..9 (pure noise) are switched off
model.history_ # every evaluation of the CV error
model.predict(x[:5])
On a 1000-sample classification task (examples/quickstart.py) the optimizer needs 16 CV
evaluations (≈1 s) versus 143 grid points (≈13 s) for GridSearchCV with sklearn.svm.SVC,
with comparable test accuracy (0.844 vs. 0.856). More comparisons (grid, random and successive-halving
search on four data sets, speed-ups between releases): Benchmarks; the ideas
to play with: Explore.
How it works
| step | method | thesis |
|---|---|---|
| training, warm start | SMO on the dual with quadratic smoothing (smo-solver) |
Ch. 7 |
| training, refinement | semismooth Newton on a + φ'(Ka/λ + b + sc) = 0 |
Ch. 8.4 |
| CV error gradient | implicit function theorem, adjoint system per fold | Ch. 9.2 |
| hyperparameter search | L-BFGS-B over (log λ, log s₁, …, log s_K) |
Ch. 9.1, 10.4 |
Reproducing the thesis
benchmarks/thesis_regression.py repeats the protocol of Table 10.4.1 (LIBSVM regression data,
30 random 80/20 splits, ε-SVR with cubic smoothing and LS-SVM):
python benchmarks/thesis_regression.py --datasets pyrim triazines mpg housing --splits 30
Documentation
Full documentation including the mathematical background: https://wotzlaff.github.io/optimized-svm/.
Build locally with uv run --group docs python scripts/build_examples.py (executes the examples)
followed by uv run --group docs zensical serve.
Citation
If you use this software, please cite the dissertation:
@phdthesis{strasdat2023,
author = {Nico Strasdat},
title = {Duality, Derivative-Based Training Methods and
Hyperparameter Optimization for Support Vector Machines},
school = {Technische Universit{\"a}t Dresden},
type = {Dissertation},
year = {2023},
url = {https://nbn-resolving.org/urn:nbn:de:bsz:14-qucosa2-874731},
note = {urn:nbn:de:bsz:14-qucosa2-874731}
}
License
BSD-3-Clause. The 2022 version (Nim backend) is preserved in the git tag legacy-2022.
Metadata
Release files for optimized-svm 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| optimized_svm-0.6.0.tar.gz | 1.3 MB | With provenance | Details for optimized_svm-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| optimized_svm-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for optimized_svm-0.6.0-py3-none-any.whl |
Total release size: 1.4 MB
Release files / optimized_svm-0.6.0.tar.gz
| Download URL | optimized_svm-0.6.0.tar.gz |
|---|---|
| Size | 1.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
50fa8ae40cc3d7901a6597323359b931d3131ab03d9b2eb3735009582bac4523
|
|
BLAKE2b-256 checksum How to use checksums |
54da794f6316f334fcb20b1068cfc3872c49036cf6a02c200e1ae201474efc92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logRelease files / optimized_svm-0.6.0-py3-none-any.whl
| Download URL | optimized_svm-0.6.0-py3-none-any.whl |
|---|---|
| Size | 59.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ededd4ab52b8373a5e308ef120e61b300b4172cb3848df5145748f493cfb4e94
|
|
BLAKE2b-256 checksum How to use checksums |
07efa525ef6361077cdbfede4ed53c4fe3b34e99a9a092581fdebc7c99999799
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logSecurity for optimized-svm 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for optimized_svm-0.6.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.