Skip to content

Commit

Permalink
Add DecisionTreeLeaf.getNodeImpurityDecrease test (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
marmichalski authored and akondas committed Mar 7, 2018
1 parent 66ca874 commit e156076
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/Classification/DecisionTree/DecisionTreeLeafTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,28 @@ public function testHTMLOutput(): void

$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());
}

public function testNodeImpurityDecreaseShouldBeZeroWhenLeafIsTerminal(): void
{
$leaf = new DecisionTreeLeaf();
$leaf->isTerminal = true;

$this->assertEquals(0.0, $leaf->getNodeImpurityDecrease(1));
}

public function testNodeImpurityDecrease(): void
{
$leaf = new DecisionTreeLeaf();
$leaf->giniIndex = 0.5;
$leaf->records = [1, 2, 3];

$leaf->leftLeaf = new DecisionTreeLeaf();
$leaf->leftLeaf->records = [5, 2];

$leaf->rightLeaf = new DecisionTreeLeaf();
$leaf->rightLeaf->records = [];
$leaf->rightLeaf->giniIndex = 0.3;

$this->assertSame(0.75, $leaf->getNodeImpurityDecrease(2));
}
}

0 comments on commit e156076

Please sign in to comment.