* Fix #120

* Add DecisionTreeLeafTest
This commit is contained in:
Marcin Michalski 2017-08-28 13:00:24 +02:00 committed by Arkadiusz Kondas
parent 136a92c82b
commit 3e2708de17
2 changed files with 29 additions and 1 deletions

View File

@ -138,9 +138,11 @@ class DecisionTreeLeaf
} else {
$col = "col_$this->columnIndex";
}
if (!preg_match('/^[<>=]{1,2}/', $value)) {
if (!preg_match('/^[<>=]{1,2}/', strval($value))) {
$value = "=$value";
}
$value = "<b>$col $value</b><br>Gini: ".number_format($this->giniIndex, 2);
}

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace tests\Classification\DecisionTree;
use Phpml\Classification\DecisionTree\DecisionTreeLeaf;
use PHPUnit\Framework\TestCase;
class DecisionTreeLeafTest extends TestCase
{
public function testHTMLOutput()
{
$leaf = new DecisionTreeLeaf();
$leaf->value = 1;
$leaf->columnIndex = 0;
$rightLeaf = new DecisionTreeLeaf();
$rightLeaf->value = '<= 2';
$rightLeaf->columnIndex = 1;
$leaf->rightLeaf = $rightLeaf;
$this->assertEquals('<table ><tr><td colspan=3 align=center style=\'border:1px solid;\'><b>col_0 =1</b><br>Gini: 0.00</td></tr><tr><td></td><td>&nbsp;</td><td valign=top align=right><b>No |</b><br><table ><tr><td colspan=3 align=center style=\'border:1px solid;\'><b>col_1 <= 2</b><br>Gini: 0.00</td></tr></table></td></tr></table>', $leaf->getHTML());
}
}