Open anoth12 opened 4 years ago
Please run var_dump($dt)
after your $dt = array($_POST['buying'], $_POST['maint'], $_POST['doors'], $_POST['persons'], $_POST['lug_bot'], $_POST['safety']);
and put the output here.
That's more helpful for debugging.
result var_dump($dt):
array(6) { [0]=> string(5) "vhigh" [1]=> string(5) "vhigh" [2]=> string(1) "2" [3]=> string(1) "2" [4]=> string(5) "small" [5]=> string(5) "small" }
after I checked several times, maybe this is because in the dataset there is no data with the same array, the error obtained is the Internal Server Error [500].
when running a classification with $ Tree-> classify (array ('vhigh', 'vhigh', '2', '2', 'small', 'small')) produces the same error 500, because there is no row in the dataset like that.
but when running the classification $ Tree-> classify (array ('vhigh', 'vhigh', '2', '2', 'small', 'med')) can return the classification results
if the decision tree calculation in R language can return the classification result that is "unnac" even though in the dataset there is no row like that.
is there a solution to this problem? :)
Will take some time this week to see if I can enhance it.
I'm trying to use your library, and there is a problem about that, when I use the classify () function with the usual array parameters, for example arrays ('data', 'data', 'data') can return the results of the classification results
but when I use an array with ajax POST parameters from the input form, suppose the array ($ _ POST ['data'], $ _POST ['data'], $ _POST ['data']) does not produce the expected classification.
dateset: https://archive.ics.uci.edu/ml/datasets/Car+Evaluation my code:
decision_action.php `<?php include_once '../config/varconfig.php'; include_once '../lib/PHP-Decision-Tree/vendor/autoload.php'; $Tree = new Jincongho\DecisionTree\DecisionTree;
if(isset($_POST['submit'])){ /**
DATA TRAINING */ $data_training = tidyData($definition['CSV_FILE_NH'], 6); $Tree->setAttrNum(6)->addTrainingSet($data_training)->startTraining();
/**
GET DATA TEST */
// if use this, cant get result clasification $dt = array($_POST['buying'], $_POST['maint'], $_POST['doors'], $_POST['persons'], $_POST['lug_bot'], $_POST['safety']); print_r($Tree->classify($dt)); // RESULT : // Jincongho\DecisionTree\TreeNode Object ( [values:protected] => Array ( [low] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => unacc ) [high] => Jincongho\DecisionTree\TreeNode Object ( [values:protected] => Array ( [vhigh] => Jincongho\DecisionTree\TreeNode Object ( [values:protected] => Array ( [big] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => unacc ) [small] => Jincongho\DecisionTree\TreeNode Object ( [values:protected] => Array ( [2] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => acc ) [4] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => unacc ) ) ) ) ) [high] => Jincongho\DecisionTree\TreeNode Object ( [values:protected] => Array ( [vhigh] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => unacc ) [high] => Jincongho\DecisionTree\TreeNode Object ( [values:protected] => Array ( [] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => unacc ) ) ) [med] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => acc ) ) ) [low] => Jincongho\DecisionTree\TreeNode Object ( [values:protected] => Array ( [5more] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => good ) [3] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => unacc ) [2] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => unacc ) [4] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => unacc ) ) ) [med] => Jincongho\DecisionTree\TreeNode Object ( [values:protected] => Array ( [] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => good ) ) ) ) ) [med] => Jincongho\DecisionTree\TreeNode Object ( [values:protected] => Array ( [small] => Jincongho\DecisionTree\TreeNode Object ( [values:protected] => Array ( [high] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => unacc ) [vhigh] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => unacc ) [low] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => acc ) [med] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => unacc ) ) ) [big] => Jincongho\DecisionTree\TreeNode Object ( [values:protected] => Array ( [3] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => good ) [2] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => good ) [5more] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => acc ) ) ) [med] => Jincongho\DecisionTree\TreeNode Object ( [values:protected] => Array ( [] => Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => unacc ) ) ) ) ) ) )
// but if use this, can get result $train = array('vhigh','vhigh','2','4','small','high'); print_r($Tree->classify($train)); // RESULT : // Jincongho\DecisionTree\TreeLabel Object ( [label:protected] => acc )
// Tampilkan datanya // echo json_encode(["hasil" => $Tree->classify($data_testing), // "data_buying" => $_POST['buying'], // "data_maint" => $_POST['maint'], // "data_doors" => $_POST['doors'], // "data_persons" => $_POST['persons'], // "data_lug_bot" => $_POST['lug_bot'], // "data_safety" => $_POST['safety'], // ]);
} // Generate file csv to array assosiative function tidyData($csv_file, $count_attr){ $csv = []; $csvnew = []; $class = null; $lines = file($csv_file, FILE_IGNORE_NEW_LINES); foreach ($lines as $key => $value){ $csv[$key] = str_getcsv($value); foreach($csv[$key] as $c => $v){ if($c == $count_attr){ $class = $v; } $csvnew[$c] = $v; unset($csvnew[$count_attr]); } $csv[$key] = array($csvnew, $class); } return $csv; } `
and ajax code in decision.php `$("document").ready(function(){ // $("#hasil1").hide(); // $("#hasil2").hide();
I hope there is a way to resolve the problem, thank you.