PHP code example of herilesmana / c45
1. Go to this page and download the library: Download herilesmana/c45 library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
herilesmana / c45 example snippets
45\C45;
$filename = __DIR__ . '/data.csv';
$c45 = new C45([
'targetAttribute' => 'play',
'type' => 'file',
'trainingData' => $filename,
'splitCriterion' => C45::SPLIT_GAIN,
]);
$tree = $c45->buildTree();
$treeString = $tree->toString();
// print generated tree
echo '<pre>';
print_r($treeString);
echo '</pre>';
$testingData = [
'outlook' => 'sunny',
'windy' => 'false',
'humidity' => 'high',
];
echo $tree->classify($testingData); // prints 'no'
5\C45;
$attributes = [...];
$data = [...];
$c45 = new C45([
'targetAttribute' => 'play',
'type' => 'array',
'trainingData' => [
'attributes' => $attributes,
'data' => $data
],
'splitCriterion' => C45::SPLIT_GAIN,
]);
$tree = $c45->buildTree();
$treeString = $tree->toString();
// print generated tree
echo '<pre>';
print_r($treeString);
echo '</pre>';
$testingData = [
'outlook' => 'sunny',
'windy' => 'false',
'humidity' => 'high',
];
echo $tree->classify($testingData); // prints 'no'
php composer.phar