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
- Use these metrics to compare classification models.
- Use these metrics to compare classification models for numbers that require
Ord
. - Cluster metrics.
- Metrics for regression models.
Traits
- A trait to be implemented by all metrics
Functions
- Function that calculated accuracy score, see accuracy.
- Completeness metric of a cluster labeling given a ground truth (range is between 0.0 and 1.0).
- Computes F1 score, see F1.
- Homogeneity metric of a cluster labeling given a ground truth (range is between 0.0 and 1.0). A cluster result satisfies homogeneity if all of its clusters contain only data points which are members of a single class.
- Computes mean absolute error, see mean absolute error.
- Computes mean squared error, see mean squared error.
- Calculated precision score, see precision.
- Computes R2 score, see R2.
- Calculated recall score, see recall
- AUC score, see AUC.
- The harmonic mean between homogeneity and completeness.