diff --git a/src/Phpml/Metric/ClassificationReport.php b/src/Phpml/Metric/ClassificationReport.php index 69209fd..31ee0b7 100644 --- a/src/Phpml/Metric/ClassificationReport.php +++ b/src/Phpml/Metric/ClassificationReport.php @@ -1,5 +1,6 @@ $actual) { $predicted = $predictedLabels[$index]; - $this->support[$actual]++; + ++$this->support[$actual]; - if($actual === $predicted) { - $truePositive[$actual]++; + if ($actual === $predicted) { + ++$truePositive[$actual]; } else { - $falsePositive[$predicted]++; - $falseNegative[$actual]++; + ++$falsePositive[$predicted]; + ++$falseNegative[$actual]; } } @@ -104,7 +105,7 @@ class ClassificationReport foreach ($truePositive as $label => $tp) { $this->precision[$label] = $tp / ($tp + $falsePositive[$label]); $this->recall[$label] = $tp / ($tp + $falseNegative[$label]); - $this->f1score[$label] = $this->computeF1Score((float)$this->precision[$label], (float)$this->recall[$label]); + $this->f1score[$label] = $this->computeF1Score((float) $this->precision[$label], (float) $this->recall[$label]); } } @@ -124,7 +125,7 @@ class ClassificationReport */ private function computeF1Score(float $precision, float $recall): float { - if(0 == ($divider = $precision+$recall)) { + if (0 == ($divider = $precision + $recall)) { return 0.0; } @@ -144,5 +145,4 @@ class ClassificationReport return $labels; } - } diff --git a/tests/Phpml/Metric/ClassificationReportTest.php b/tests/Phpml/Metric/ClassificationReportTest.php index 58520be..2f7bc1a 100644 --- a/tests/Phpml/Metric/ClassificationReportTest.php +++ b/tests/Phpml/Metric/ClassificationReportTest.php @@ -1,5 +1,6 @@ 1, 'ant' => 1, 'bird' => 3]; $average = ['precision' => 0.75, 'recall' => 0.83, 'f1score' => 0.73]; - $this->assertEquals($precision, $report->getPrecision(), '', 0.01); $this->assertEquals($recall, $report->getRecall(), '', 0.01); $this->assertEquals($f1score, $report->getF1score(), '', 0.01); $this->assertEquals($support, $report->getSupport(), '', 0.01); $this->assertEquals($average, $report->getAverage(), '', 0.01); } - }