public function testTwoNodesTwoEdgesNull() { $edges = [new Edge("yes", null, new DecisionTreeNode("yes", [new Edge("yes", 4, null)])), new Edge("no", null, new DecisionTreeNode("yes", [new Edge("yes", 8, null)]))]; $decision_tree = new DecisionTree(new DecisionTreeNode("no", $edges)); $score = $decision_tree->calcScore(null, null); $this->assertEquals(null, $score, "Scores didn't match."); }
<?php include 'inc.general.php'; $cmd = Util::makeVar('cmd'); $treeID = Util::makeVar('treeID'); $branchID = Util::makeVar('branchID'); $branchContent = Util::makeVar('branchContent'); $forks = Util::makeVar('forks'); $revision = Util::makeVar('revision'); $tree = new DecisionTree($treeID); if (!empty($revision)) { $tree->loadRevision($revision); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Interactive Decision Tree - Editor</title> <link href="css/editor.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/editor.js"></script> </head> <body> <h1>Interactive Decision Tree - Editor</h1> <div id="debug"></div> <?php switch ($cmd) { case 'edit-tree': case 'new-tree':
<?php error_reporting(E_ALL | E_STRICT); echo "Using training data to generate Decision tree...\n"; $dec_tree = new DecisionTree('historical_data.csv', 0); echo "Decision tree using ID3:\n"; $dec_tree->display(); echo "Prediction on new data set\n"; $dec_tree->predict_outcome('input_data.csv'); exit; class Tree { protected $root; private $currentNode; public function __construct($root) { $this->root = $root; } public function display() { $this->root->display(0); } } class Node { public $value; public $namedBranches; public function __construct($new_item) { $this->value = $new_item; $this->namedBranches = array();