Module smartcore::metrics

source ·
Expand description

Functions for assessing prediction error.

Metric functions

One way to build machine learning models is to use a constructive feedback loop through model evaluation. In a feedback loop you build your model first, then you get feedback from metrics, improve it and repeat until your model achieve desirable performance. Evaluation metrics helps to explain the performance of a model and compare models based on an objective criterion.

Choosing the right metric is crucial while evaluating machine learning models. In smartcore you will find metrics for these classes of ML models:

Example:

use smartcore::linalg::basic::matrix::DenseMatrix;
use smartcore::linear::logistic_regression::LogisticRegression;
use smartcore::metrics::*;

let x = DenseMatrix::from_2d_array(&[
            &[5.1, 3.5, 1.4, 0.2],
            &[4.9, 3.0, 1.4, 0.2],
            &[4.7, 3.2, 1.3, 0.2],
            &[4.6, 3.1, 1.5, 0.2],
            &[5.0, 3.6, 1.4, 0.2],
            &[5.4, 3.9, 1.7, 0.4],
            &[4.6, 3.4, 1.4, 0.3],
            &[5.0, 3.4, 1.5, 0.2],
            &[4.4, 2.9, 1.4, 0.2],
            &[4.9, 3.1, 1.5, 0.1],
            &[7.0, 3.2, 4.7, 1.4],
            &[6.4, 3.2, 4.5, 1.5],
            &[6.9, 3.1, 4.9, 1.5],
            &[5.5, 2.3, 4.0, 1.3],
            &[6.5, 2.8, 4.6, 1.5],
            &[5.7, 2.8, 4.5, 1.3],
            &[6.3, 3.3, 4.7, 1.6],
            &[4.9, 2.4, 3.3, 1.0],
            &[6.6, 2.9, 4.6, 1.3],
            &[5.2, 2.7, 3.9, 1.4],
  ]);
let y: Vec<i8> = vec![
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  ];

let lr = LogisticRegression::fit(&x, &y, Default::default()).unwrap();

let y_hat = lr.predict(&x).unwrap();

let acc = ClassificationMetricsOrd::accuracy().get_score(&y, &y_hat);
// or
let acc = accuracy(&y, &y_hat);

Modules

  • Accuracy score.
  • Area Under the Receiver Operating Characteristic Curve (ROC AUC)
  • Compute the homogeneity, completeness and V-Measure scores.
  • Multitude of distance metrics are defined here
  • F1 score, also known as balanced F-score or F-measure.
  • Mean absolute error regression loss.
  • Mean squared error regression loss.
  • Computes the precision.
  • Coefficient of determination (R2). Coefficient of Determination (R2)
  • Computes the recall.

Structs

Traits

  • A trait to be implemented by all metrics

Functions