PHP code example of juliardi / c45

1. Go to this page and download the library: Download juliardi/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/ */

    

juliardi / c45 example snippets




45\C45;

$filename = __DIR__ . '/data.csv';

$c45 = new C45([
                'targetAttribute' => 'play',
                'trainingFile' => $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'

php composer.phar