dev-master
9999999-dev
MIT
The Requires
- juliardi/data-reader ^1.0
- php >=5.5
by Muhammad Safri Juliardi
0.0.1
0.0.1.0
MIT
The Requires
by Muhammad Safri Juliardi
Wallogit.com
2017 © Pedro Pelรกez
C45 algorithm implementation in pure PHP, (*1)
NOTE : this implementation doesn't support numeric value for data training. I don't have any plan to implement it. Feel free to send a pull request., (*2)
The preferred way to install this extension is through composer., (*3)
Either run, (*4)
php composer.phar require --prefer-dist juliardi/c45 "*"
or add, (*5)
"juliardi/c45": "*"
to the require section of your composer.json file., (*6)
This library doesn't need any special configuration. You can use it as is. However, there are a few requirement that must be met in order to make this library run as intended. 1. You can only use CSV file as input for training data. It is a bad decision and I admit it. However as of now i don't have time to implements a more generic way to read training data. 2. The first line of the CSV file MUST be the attribute name and MUST be quoted in double quotes, (*7)
Here is an example of a valid CSV for training :, (*8)
"outlook", "windy", "humidity", "play" sunny, false, high, no sunny, true, high, no sunny, false, high, no sunny, false, medium, yes sunny, true, medium, yes overcast, false, medium, yes overcast, true, medium, yes overcast, true, high, yes overcast, false, medium, yes rain, false, high, yes rain, false, medium, yes rain, true, medium, no rain, false, medium, yes rain, true, medium, no
Assuming that you have the following directory structure :, (*9)
. โโโ src | โโโ index.php | โโโ data.csv โโโ vendor โโโ composer.json
You can use PHP-C45 in your index.php like this :, (*10)
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use C45\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 '
';
print_r($treeString);
echo '
';
$testingData = [
'outlook' => 'sunny',
'windy' => 'false',
'humidity' => 'high',
];
echo $tree->classify($testingData); // prints 'no'
MIT
MIT