Library to construct a confusion matrix and retrieve statistical information from it. https://crates.io/crates/confusion_matrix
Peter Lane 84e94631c2 corrected mistake in example | 1 år sedan | |
---|---|---|
examples | 1 år sedan | |
src | 1 år sedan | |
Cargo.toml | 1 år sedan | |
README.md | 1 år sedan |
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")] = 5;
cm[("neg", "neg")] = 20;
cm[("neg", "pos")] = 3;
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.