php-cs-fixer

This commit is contained in:
Arkadiusz Kondas 2016-07-19 21:59:23 +02:00
parent 9665457159
commit 074dcf7470
2 changed files with 12 additions and 14 deletions

View File

@ -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;
}
}

View File

@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);
declare (strict_types = 1);
namespace tests\Phpml\Metric;
@ -7,11 +8,10 @@ use Phpml\Metric\ClassificationReport;
class ClassificationReportTest extends \PHPUnit_Framework_TestCase
{
public function testClassificationReportGenerateWithStringLabels()
{
$labels = ['cat', 'ant', 'bird', 'bird', 'bird'];
$predicted = ['cat', 'cat', 'bird', 'bird', 'ant'];
$predicted = ['cat', 'cat', 'bird', 'bird', 'ant'];
$report = new ClassificationReport($labels, $predicted);
@ -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);
}
}