value = 1; $leaf->columnIndex = 0; $rightLeaf = new DecisionTreeLeaf(); $rightLeaf->value = '<= 2'; $rightLeaf->columnIndex = 1; $leaf->rightLeaf = $rightLeaf; self::assertEquals( '
col_0 =1
Gini: 0.00
 No |
col_1 <= 2
Gini: 0.00
', $leaf->getHTML() ); } public function testNodeImpurityDecreaseShouldBeZeroWhenLeafIsTerminal(): void { $leaf = new DecisionTreeLeaf(); $leaf->isTerminal = true; self::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; self::assertSame(0.75, $leaf->getNodeImpurityDecrease(2)); } }