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],
]).unwrap();
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
- Accuracy score.
- auc
- Area Under the Receiver Operating Characteristic Curve (ROC AUC)
- cluster_
hcv - Compute the homogeneity, completeness and V-Measure scores.
- distance
- Multitude of distance metrics are defined here
- f1
- F1 score, also known as balanced F-score or F-measure.
- mean_
absolute_ error - Mean absolute error regression loss.
- mean_
squared_ error - Mean squared error regression loss.
- precision
- Computes the precision.
- r2
- Coefficient of determination (R2). Coefficient of Determination (R2)
- recall
- Computes the recall.
Structs§
- Classification
Metrics - Use these metrics to compare classification models.
- Classification
Metrics Ord - Use these metrics to compare classification models for
numbers that require
Ord
. - Cluster
Metrics - Cluster metrics.
- Regression
Metrics - Metrics for regression models.
Traits§
- Metrics
- A trait to be implemented by all metrics
Functions§
- accuracy
- Function that calculated accuracy score, see accuracy.
- completeness_
score - Completeness metric of a cluster labeling given a ground truth (range is between 0.0 and 1.0).
- f1
- Computes F1 score, see F1.
- homogeneity_
score - 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.
- mean_
absolute_ error - Computes mean absolute error, see mean absolute error.
- mean_
squared_ error - Computes mean squared error, see mean squared error.
- precision
- Calculated precision score, see precision.
- r2
- Computes R2 score, see R2.
- recall
- Calculated recall score, see recall
- roc_
auc_ score - AUC score, see AUC.
- v_
measure_ score - The harmonic mean between homogeneity and completeness.