mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-22 04:55:10 +00:00
php-cs-fixer
This commit is contained in:
parent
9665457159
commit
074dcf7470
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace Phpml\Metric;
|
||||
|
||||
@ -40,13 +41,13 @@ class ClassificationReport
|
||||
|
||||
foreach ($actualLabels as $index => $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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace tests\Phpml\Metric;
|
||||
|
||||
@ -7,7 +8,6 @@ use Phpml\Metric\ClassificationReport;
|
||||
|
||||
class ClassificationReportTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testClassificationReportGenerateWithStringLabels()
|
||||
{
|
||||
$labels = ['cat', 'ant', 'bird', 'bird', 'bird'];
|
||||
@ -21,12 +21,10 @@ class ClassificationReportTest extends \PHPUnit_Framework_TestCase
|
||||
$support = ['cat' => 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user