Skip to content

Commit

Permalink
php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas committed Jul 19, 2016
1 parent 9665457 commit 074dcf7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
18 changes: 9 additions & 9 deletions src/Phpml/Metric/ClassificationReport.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare (strict_types = 1);

namespace Phpml\Metric;

Expand Down Expand Up @@ -40,13 +41,13 @@ public function __construct(array $actualLabels, array $predictedLabels)

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

Expand Down Expand Up @@ -104,7 +105,7 @@ private function computeMetrics(array $truePositive, array $falsePositive, array
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]);
}
}

Expand All @@ -124,7 +125,7 @@ private function computeAverage()
*/
private function computeF1Score(float $precision, float $recall): float
{
if(0 == ($divider = $precision+$recall)) {
if (0 == ($divider = $precision + $recall)) {
return 0.0;
}

Expand All @@ -144,5 +145,4 @@ private static function getLabelIndexedArray(array $labels): array

return $labels;
}

}
8 changes: 3 additions & 5 deletions tests/Phpml/Metric/ClassificationReportTest.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php
declare(strict_types = 1);

declare (strict_types = 1);

namespace tests\Phpml\Metric;

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);

Expand All @@ -21,12 +21,10 @@ public function testClassificationReportGenerateWithStringLabels()
$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);
}

}

0 comments on commit 074dcf7

Please sign in to comment.