Exemple #1
0
 function print_importance($out = STDOUT)
 {
     /*
      Prints the importance data
     */
     print_importance($out);
 }
Exemple #2
0
 function summarize($out = STDOUT, $format = 1)
 {
     /* Prints summary grouping distribution as class header and details */
     $distribution = $this->get_data_distribution();
     fwrite($out, "Data distribution:\n");
     print_distribution($distribution, $out);
     fwrite($out, "\n\n");
     $groups = $this->group_prediction();
     $predictions = $this->get_prediction_distribution($groups);
     fwrite($out, "Predicted distribution:\n");
     $a_to_print = array();
     foreach ($predictions as $key => $value) {
         array_push($a_to_print, array($key, $value));
     }
     $tree = $this->tree;
     print_distribution($a_to_print, $out);
     fwrite($out, "\n\n");
     if ($this->field_importance) {
         fwrite($out, "Field importance:\n");
         print_importance($this, $out);
     }
     $groups = $this->extract_common_path($groups);
     fwrite($out, "\n\nRules summary:");
     foreach ($a_to_print as $x) {
         $group = $x[0];
         $details = $groups[$group]["details"];
         $path = new Path($groups[$group]["total"][0]);
         $data_per_group = $groups[$group]["total"][1] * 1.0 / $tree->count;
         $pred_per_group = $groups[$group]["total"][2] * 1.0 / $tree->count;
         fwrite($out, "\n\n" . $group . " : (data " . number_format(round($data_per_group, 4) * 100, 2) . "% / prediction " . number_format(round($pred_per_group, 4) * 100, 2) . "%) " . $path->to_rules($this->fields, "name", $format));
         if (count($details) == 0) {
             fwrite($out, "\n     The model will never predict this class\n");
         } else {
             if (count($details) == 1) {
                 $subgroup = $details[0];
                 fwrite($out, $this->confidence_error($subgroup[2], $subgroup[3], $tree) . "\n");
             } else {
                 fwrite($out, "\n");
                 foreach ($details as $key => $subgroup) {
                     $pred_per_sgroup = $subgroup[1] * 1.0 / $groups[$group]["total"][2];
                     $path = new Path($subgroup[0]);
                     $path_chain = (!is_null($path->predicates) or $path->predicates == false) ? $path->to_rules($this->fields, 'name', $format) : "(root node)";
                     fwrite($out, "    · " . number_format(round($pred_per_sgroup, 4) * 100, 2) . "%: " . $path_chain . $this->confidence_error($subgroup[2], $subgroup[3], $tree) . "\n");
                 }
             }
         }
     }
     fclose($out);
 }