Skip to content

Commit e156076

Browse files
marmichalskiakondas
authored andcommitted
Add DecisionTreeLeaf.getNodeImpurityDecrease test (#261)
1 parent 66ca874 commit e156076

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/Classification/DecisionTree/DecisionTreeLeafTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,28 @@ public function testHTMLOutput(): void
2323

2424
$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());
2525
}
26+
27+
public function testNodeImpurityDecreaseShouldBeZeroWhenLeafIsTerminal(): void
28+
{
29+
$leaf = new DecisionTreeLeaf();
30+
$leaf->isTerminal = true;
31+
32+
$this->assertEquals(0.0, $leaf->getNodeImpurityDecrease(1));
33+
}
34+
35+
public function testNodeImpurityDecrease(): void
36+
{
37+
$leaf = new DecisionTreeLeaf();
38+
$leaf->giniIndex = 0.5;
39+
$leaf->records = [1, 2, 3];
40+
41+
$leaf->leftLeaf = new DecisionTreeLeaf();
42+
$leaf->leftLeaf->records = [5, 2];
43+
44+
$leaf->rightLeaf = new DecisionTreeLeaf();
45+
$leaf->rightLeaf->records = [];
46+
$leaf->rightLeaf->giniIndex = 0.3;
47+
48+
$this->assertSame(0.75, $leaf->getNodeImpurityDecrease(2));
49+
}
2650
}

0 commit comments

Comments
 (0)