Skip to main content

svmloader

PyPI License: GPL v3

Fast loader for libsvm / svmlight sparse data files in Python (Cython), an alternative to sklearn.datasets.load_svmlight_file. svmloader loads them as scipy.sparse.csr_matrix matrices and numpy label arrays.

It is not fully equivalent to sklearn.datasets.load_svmlight_file, in particular query_id are not supported and dtype is restricted.

The types of data and labels are distinguished. The labels types supported are int and float (default int), and data can be parsed as numpy.float64 or numpy.float32 type (float64 by default).

Compressed data in .gz or .bz2 format is supported as well (see Benchmarks for the cost of bz2 decompression).

Install

Simply use pip install svmloader (Python 3.9+).

Alternatively, you can clone the repository and run pip install ..

Dependencies :

  • numpy
  • scipy

Usage

from svmloader import load_svmfile, load_svmfiles

# X is a scipy.sparse.csr_matrix, y a numpy array of labels.
# Column indices are zero-based by default: pass zero_based=False
# for one-based files (as in the libsvm datasets).
X, y = load_svmfile('train.libsvm', zero_based=False)

# float32 data, float labels, bz2 file decompressed on the fly
X, y = load_svmfile('train.libsvm.bz2', dtype='f', ltype='d', zero_based=False)

# several files at once, with the same number of columns
X_train, y_train, X_test, y_test = load_svmfiles(['train.libsvm', 'test.libsvm.gz'], zero_based=False)

Documentation

See here.

Benchmarks

Benchmarks on data taken from libsvm datasets, with Python 3.12, numpy 2.5, scipy 1.18 and scikit-learn 1.9.1 on an Intel Core i7-3770. Times are the best of 3 runs (2 for rcv1) in a fresh process, with the files in the page cache.

dataset (shape, nonzeros) sklearn 1.9 svmloader
mnist.scale (60000x780, 8994156) 5.0s 0.88s
rcv1_test.multiclass (518571x47236, 33486015) 21.1s 7.6s

svmloader is 5-6x faster than scikit-learn on mnist and about 3x faster on rcv1. For reference, libsvm's svm_read_problem takes 5.0s on mnist.

Compressed files are decompressed on the fly. bzip2 decompression is CPU-bound and much slower than parsing: on the same machine, loading mnist.bz2 takes 3-8s (versus 0.9s uncompressed) and the 815 MB rcv1 file takes 60-100s from .bz2 (versus 7.6s uncompressed). The range reflects CPU throttling under sustained decompression; .gz files decompress much faster.

Metadata

Release files for svmloader 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for svmloader 0.5.2
File Size Uploaded Provenance
svmloader-0.5.2.tar.gz 233.3 kB Without provenance Details

Release files / svmloader-0.5.2.tar.gz

Download URL svmloader-0.5.2.tar.gz
Size 233.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9d71c51371ebbc638a611eacb1d915a4214ab035b64f9053ee436850a648671b
BLAKE2b-256 checksum
How to use checksums
e04052f90faf228162dea66bb66def6f0fdfbf7eb9eb9f76eb14f72fa4d9059b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for svmloader 0.5.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page