3 releases (1 stable)

Uses old Rust 2015

1.0.0 Oct 24, 2019
0.1.1 Mar 1, 2019
0.1.0 Feb 28, 2019

#574 in Machine learning

Download history 40/week @ 2024-07-22 126/week @ 2024-07-29 43/week @ 2024-08-05 35/week @ 2024-08-12 49/week @ 2024-08-19 32/week @ 2024-08-26 89/week @ 2024-09-02 25/week @ 2024-09-09 24/week @ 2024-09-16 59/week @ 2024-09-23 22/week @ 2024-09-30 22/week @ 2024-10-07 24/week @ 2024-10-14 17/week @ 2024-10-21 13/week @ 2024-10-28 67/week @ 2024-11-04

123 downloads per month
Used in vaporetto

MIT license

1MB
7K SLoC

C++ 3K SLoC // 0.1% comments C 2K SLoC // 0.0% comments Rust 1K SLoC // 0.0% comments Python 644 SLoC // 0.2% comments Objective-C 22 SLoC

Contains (Windows DLL, 270KB) liblinear/windows/liblinear.dll, (DOS exe, 270KB) liblinear/windows/train.exe, (DOS exe, 215KB) liblinear/windows/predict.exe, (DOS exe, 79KB) liblinear/windows/train.mexw64, (DOS exe, 25KB) liblinear/windows/predict.mexw64, (DOS exe, 15KB) liblinear/windows/libsvmread.mexw64 and 1 more.

Latest Version deps.svg docs MIT

liblinear-rs

Rust bindings for the liblinear C/C++ library. Provides a thin (but rustic) wrapper around the original C-interface exposed by the library.

Usage

Use the liblinear::Builder API to train a model on sparse features and predict the class of a new instance.

extern crate liblinear;
use liblinear::*;

let x: Vec<Vec<(u32, f64)>> = vec![
        vec![(1, 0.1), (3, 0.2)],
        vec![(3, 9.9)],
        vec![(1, 0.2), (2, 3.2)],
    ];
let y = vec![0.0, 1.0, 0.0];

let mut model_builder = liblinear::Builder::new();
model_builder
    .problem()
    .input_data(util::TrainingInput::from_sparse_features(y, x).unwrap())
    .bias(0f64);
model_builder
    .parameters()
    .solver_type(SolverType::L2R_LR)
    .stopping_criterion(0.1f64)
    .constraints_violation_cost(0.1f64)
    .regression_loss_sensitivity(1f64);

let model = model_builder.build_model().unwrap();
assert_eq!(model.num_classes(), 2);

let predicted_class = model
    .predict(util::PredictionInput::from_sparse_features(vec![(1u32, 2.2f64)]).unwrap())
    .unwrap();
println!(predicted_class);

More examples can be found in the bundled unit tests.

Changelog

1.0.0 - Update liblinear to v230 (breaking changes), minor changes and fixes.
0.1.1 - Added readme, minor documentation fixes.
0.1.0 - Initial release.

Dependencies