Crates.io | confusion_matrix |
lib.rs | confusion_matrix |
version | 1.1.0 |
source | src |
created_at | 2021-02-28 16:19:13.391524 |
updated_at | 2023-11-22 12:13:11.923804 |
description | Confusion matrix implementation for storing results from a classification experiment and providing statistical information. |
homepage | |
repository | https://notabug.org/peterlane/confusion-matrix-rust |
max_upload_size | |
id | 361851 |
size | 36,320 |
For storing results from a classification experiment and providing statistical information.
A confusion matrix is used in data-mining as a summary of the performance of a classification algorithm. Each row represents the actual class of an instance, and each column represents the predicted class of that instance, i.e. the class that they were classified as. Numbers at each (row, column) reflect the total number of instances of actual class "row" which were predicted to fall in class "column".
A two-class example is:
Predicted Predicted |
Positive Negative | Actual
------------------------------+------------
a b | Positive
c d | Negative
Here, the value:
From this table we can calculate statistics like:
Features:
The following example shows how to create a confusion matrix, add some results, and then print some statistics and the table itself.
use confusion_matrix;
fn main() {
let mut cm = confusion_matrix::new();
cm[("pos", "pos")] = 10;
cm[("pos", "neg")] = 3;
cm[("neg", "neg")] = 20;
cm[("neg", "pos")] = 5;
println!("Precision: {}", cm.precision("pos"));
println!("Recall: {}", cm.recall("pos"));
println!("MCC: {}", cm.matthews_correlation("pos"));
println!("");
println!("{}", cm);
}
Output:
Precision: 0.7692307692307693
Recall: 0.6666666666666666
MCC: 0.5524850114241865
Predicted |
neg pos | Actual
----------+-------
20 3 | neg
5 10 | pos
Copyright (c) 2021-23, Peter Lane peterlane@gmx.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.