2016-07-11 22:11:18 +00:00
|
|
|
# Confusion Matrix
|
|
|
|
|
2019-11-02 10:41:34 +00:00
|
|
|
Class for computing confusion matrix to evaluate the accuracy of a classification.
|
2016-07-11 22:11:18 +00:00
|
|
|
|
|
|
|
### Example (all targets)
|
|
|
|
|
|
|
|
Compute ConfusionMatrix for all targets.
|
|
|
|
|
|
|
|
```
|
|
|
|
use Phpml\Metric\ConfusionMatrix;
|
|
|
|
|
|
|
|
$actualTargets = [2, 0, 2, 2, 0, 1];
|
|
|
|
$predictedTargets = [0, 0, 2, 2, 0, 2];
|
|
|
|
|
|
|
|
$confusionMatrix = ConfusionMatrix::compute($actualTargets, $predictedTargets)
|
|
|
|
|
|
|
|
/*
|
|
|
|
$confusionMatrix = [
|
|
|
|
[2, 0, 0],
|
|
|
|
[0, 0, 1],
|
|
|
|
[1, 0, 2],
|
|
|
|
];
|
|
|
|
*/
|
|
|
|
```
|
|
|
|
|
|
|
|
### Example (chosen targets)
|
|
|
|
|
|
|
|
Compute ConfusionMatrix for chosen targets.
|
|
|
|
|
|
|
|
```
|
|
|
|
use Phpml\Metric\ConfusionMatrix;
|
|
|
|
|
|
|
|
$actualTargets = ['cat', 'ant', 'cat', 'cat', 'ant', 'bird'];
|
|
|
|
$predictedTargets = ['ant', 'ant', 'cat', 'cat', 'ant', 'cat'];
|
|
|
|
|
|
|
|
$confusionMatrix = ConfusionMatrix::compute($actualTargets, $predictedTargets, ['ant', 'bird'])
|
|
|
|
|
|
|
|
/*
|
|
|
|
$confusionMatrix = [
|
|
|
|
[2, 0],
|
|
|
|
[0, 0],
|
|
|
|
];
|
|
|
|
*/
|
|
|
|
```
|