Fast dual proximal and Frank-Wolfe SVM optimizers.
Project description
dual-fw-svm
Fast linear SVM solvers built around dual proximal updates and matrix-wise Frank-Wolfe optimization. The implementation is designed for experimentation with memory-efficient SVM training on linear datasets.
What Is Included
BinaryL2DualSVM: a proximal-gradient solver for binary L2-SVM dual variables with an efficient equality-constrained nonnegative projection.MulticlassFrankWolfeSVM: matrix-wise Frank-Wolfe for Crammer-Singer (formulation="cs") and Weston-Watkins (formulation="ww") multiclass SVMs.BlockCoordinateFrankWolfeSVM: stochastic row-wise Frank-Wolfe baseline.benchmarks/compare_svm.py: compares these solvers with common sklearn baselines:LinearSVC,LinearSVC(multi_class="crammer_singer"), one-vs-restLinearSVC, andSGDClassifier.
Why It Is Fast
The default linear solvers avoid materializing the large Gram matrix. Binary
training uses X.T @ (y * alpha) and multiclass training keeps
W = X.T @ alpha, which is the main speed and memory choice for large
datasets. For small custom-kernel experiments, both main solvers also accept
kernel="precomputed" with a train Gram matrix during fit and a
test-by-train kernel matrix during prediction.
Install
pip install dual-fw-svm
For benchmark and test dependencies:
pip install "dual-fw-svm[benchmark,test]"
Quick Start
from dual_fw_svm import BinaryL2DualSVM, MulticlassFrankWolfeSVM
binary = BinaryL2DualSVM(C=1.0, max_iter=1000, tol=1e-5)
binary.fit(X_train, y_train)
binary_pred = binary.predict(X_test)
multi = MulticlassFrankWolfeSVM(C=1.0, formulation="cs", max_iter=500)
multi.fit(X_train, y_train)
multi_pred = multi.predict(X_test)
Precomputed Kernels
from dual_fw_svm import BinaryL2DualSVM
K_train = X_train @ X_train.T
K_test = X_test @ X_train.T
model = BinaryL2DualSVM(C=1.0, kernel="precomputed")
model.fit(K_train, y_train)
pred = model.predict(K_test)
Benchmark Snapshot
Current local benchmark results on synthetic binary data and sklearn digits:
| Task | Method | Fit time | Test accuracy |
|---|---|---|---|
| binary | sklearn LinearSVC | 0.0116s | 0.8617 |
| binary | L2 dual prox | 0.2297s | 0.8633 |
| multiclass | CS matrix-FW | 0.0762s | 0.9593 |
| multiclass | WW matrix-FW | 0.0796s | 0.9537 |
| multiclass | sklearn LinearSVC CS | 0.1349s | 0.9537 |
| multiclass | sklearn SGD hinge | 0.4333s | 0.9537 |
The binary solver is a transparent Python implementation and is not expected to beat LIBLINEAR on small dense problems. The matrix-wise multiclass solver is the main speed-oriented implementation.
Development
Run tests:
python -m unittest discover -s tests
Run the benchmark:
python benchmarks/compare_svm.py
The benchmark writes:
benchmarks/results_latest.csv
Notes
BinaryL2DualSVM.Cuses this squared-slack scaling:0.5 ||w||^2 + C/2 * sum_i xi_i^2.- The multiclass implementations use a no-bias formulation. Standardizing dense features before fitting is recommended for faster convergence and fair comparison.
- The benchmark uses
LinearSVC(C=C/2, loss="squared_hinge")for the binary sklearn baseline because sklearn's squared-hinge objective uses a slightly different constant factor.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dual_fw_svm-0.1.3.tar.gz.
File metadata
- Download URL: dual_fw_svm-0.1.3.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5e89d57c92e5ffcf1f7bb819206e51cc35bd4991cd7704a65206011ccc01369
|
|
| MD5 |
d38c95811051f57b692e0b0c83a2e962
|
|
| BLAKE2b-256 |
8fafb779e9f16f09d218a0b53236366aed489361d926a4e84206518f478a4b08
|
File details
Details for the file dual_fw_svm-0.1.3-py3-none-any.whl.
File metadata
- Download URL: dual_fw_svm-0.1.3-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcaddb5f5e35e2bfbb472e342b6d9ef3307ba82adf15cc008fb33148028cf08d
|
|
| MD5 |
d46fe4d7c0ab4bc026f5bbcdfb351a22
|
|
| BLAKE2b-256 |
d2d12d92a11b9293aa0795700e30c3070f4c5ec6451bfce2de80f77457ce9140
|