columnIndex];
if ($this->isContinuous) {
$op = $this->operator;
$value = $this->numericValue;
$recordField = strval($recordField);
eval("\$result = $recordField $op $value;");
return $result;
}
return $recordField == $this->value;
}
/**
* Returns Mean Decrease Impurity (MDI) in the node.
* For terminal nodes, this value is equal to 0
*
* @param int $parentRecordCount
*
* @return float
*/
public function getNodeImpurityDecrease(int $parentRecordCount)
{
if ($this->isTerminal) {
return 0.0;
}
$nodeSampleCount = (float) count($this->records);
$iT = $this->giniIndex;
if ($this->leftLeaf) {
$pL = count($this->leftLeaf->records) / $nodeSampleCount;
$iT -= $pL * $this->leftLeaf->giniIndex;
}
if ($this->rightLeaf) {
$pR = count($this->rightLeaf->records) / $nodeSampleCount;
$iT -= $pR * $this->rightLeaf->giniIndex;
}
return $iT * $nodeSampleCount / $parentRecordCount;
}
/**
* Returns HTML representation of the node including children nodes
*
* @param $columnNames
*
* @return string
*/
public function getHTML($columnNames = null)
{
if ($this->isTerminal) {
$value = "$this->classValue";
} else {
$value = $this->value;
if ($columnNames !== null) {
$col = $columnNames[$this->columnIndex];
} else {
$col = "col_$this->columnIndex";
}
if (!preg_match('/^[<>=]{1,2}/', $value)) {
$value = "=$value";
}
$value = "$col $value
Gini: ".number_format($this->giniIndex, 2);
}
$str = "
$value | ||||
| Yes '.$this->leftLeaf->getHTML($columnNames).' | ';
} else {
$str .= ''; } $str .= ' | '; if ($this->rightLeaf) { $str .= ' | No | '.$this->rightLeaf->getHTML($columnNames).' | ';
} else {
$str .= ''; } $str .= ' |