[][src]Trait liblinear::LibLinearModel

pub trait LibLinearModel: HasLibLinearProblem + HasLibLinearParameter {
    fn predict(&self, features: PredictionInput) -> Result<f64, ModelError>;
fn predict_values(
        &self,
        features: PredictionInput
    ) -> Result<(Vec<f64>, f64), ModelError>;
fn predict_probabilities(
        &self,
        features: PredictionInput
    ) -> Result<(Vec<f64>, f64), ModelError>;
fn feature_coefficient(&self, feature_index: i32, label_index: i32) -> f64;
fn label_bias(&self, label_index: i32) -> f64;
fn bias(&self) -> f64;
fn labels(&self) -> &Vec<i32>;
fn num_classes(&self) -> usize;
fn num_features(&self) -> usize;
fn save_to_disk(&self, file_path: &str) -> Result<(), ModelError>; }

Represents a linear model that can be used for prediction.

Required methods

fn predict(&self, features: PredictionInput) -> Result<f64, ModelError>

Returns one of the following values:

  • For a classification model, the predicted class is returned.
  • For a regression model, the function value of x calculated using the model is returned.

fn predict_values(
    &self,
    features: PredictionInput
) -> Result<(Vec<f64>, f64), ModelError>

Returns a tuple of the following values:

  • A list of decision values. If k is the number of classes, each element includes results of predicting k binary-class SVMs. If k=2 and solver is not MCSVM_CS, only one decision value is returned.

    The values correspond to the classes returned by the labels method.

  • The class with the highest decision value.

fn predict_probabilities(
    &self,
    features: PredictionInput
) -> Result<(Vec<f64>, f64), ModelError>

Returns a tuple of the following values:

  • A list of probability estimates. each element contains k values indicating the probability that the testing instance is in each class.

    The values correspond to the classes returned by the labels method.

  • The class with the highest probability.

Only supports logistic regression solvers.

fn feature_coefficient(&self, feature_index: i32, label_index: i32) -> f64

Returns the coefficient for the feature with the given index and the class with the given (label) index.

Note that while feature indices start from 1, label indices start from 0. If the feature index is not in the valid range, a zero value will be returned.

For classification models, if the label index is not in the valid range, a zero value will be returned. For regression models, the label index is ignored.

fn label_bias(&self, label_index: i32) -> f64

Returns the bias term corresponding to the class with the given index.

For classification models, if label index is not in a valid range, a zero value will be returned. For regression models, the label index is ignored.

fn bias(&self) -> f64

Returns the bias of the input data with which the model was trained.

fn labels(&self) -> &Vec<i32>

Returns the labels/classes learned by the model.

fn num_classes(&self) -> usize

Returns the number of classes of the model.

For regression models, 2 is returned.

fn num_features(&self) -> usize

Returns the number of features of the input data with which the model was trained.

fn save_to_disk(&self, file_path: &str) -> Result<(), ModelError>

Serializes the model and saves it to disk.

Only serializes the learned model weights, labels and solver type.

Loading content...

Implementors

Loading content...