Skip to content

Latest commit

 

History

History
58 lines (46 loc) · 1.51 KB

README.md

File metadata and controls

58 lines (46 loc) · 1.51 KB

Latest Version deps.svg docs MIT

liblinear

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 liblinear::{
    Model,
    Parameters,
    TrainingInput,
    PredictionInput,
    solver::L2R_LR,
    model::traits::*,
    parameter::traits::*,
    solver::traits::*,
};

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 params = Parameters::<L2R_LR>::default();
params
    .bias(0f64)
    .stopping_tolerance(0.1f64)
    .constraints_violation_cost(0.1f64);

let model = Model::train(&TrainingInput::from_sparse_features(y, x).unwrap(), &params).unwrap();

let predicted_class = model
    .predict(&PredictionInput::from_sparse_features(vec![(3u32, 9.9f64)]).unwrap())
    .unwrap();
println!("{}", predicted_class);

Please refer to the API docs for more information.

Changelog

Please refer to the detailed changelog.