Skip to content

Commit

Permalink
update example of usage
Browse files Browse the repository at this point in the history
  • Loading branch information
agoenks29D committed Apr 24, 2022
1 parent 2c12d65 commit 91e369f
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
127 changes: 127 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,133 @@ print_r ($c45->buildTree()->toArray()); // print as array
echo "</pre>";
```

## Initialize Data from Array

```php
$c45 = new Algorithm\C45();
$input = new Algorithm\C45\DataInput;
$data = array(
array(
"OUTLOOK" => "Sunny",
"TEMPERATURE" => "Hot",
"HUMIDITY" => "High",
"WINDY" => "False",
"PLAY" => "No"
),
array(
"OUTLOOK" => "Sunny",
"TEMPERATURE" => "Hot",
"HUMIDITY" => "High",
"WINDY" => "True",
"PLAY" => "No"
),
array(
"OUTLOOK" => "Cloudy",
"TEMPERATURE" => "Hot",
"HUMIDITY" => "High",
"WINDY" => "False",
"PLAY" => "Yes"
),
array(
"OUTLOOK" => "Rainy",
"TEMPERATURE" => "Mild",
"HUMIDITY" => "High",
"WINDY" => "False",
"PLAY" => "Yes"
),
array(
"OUTLOOK" => "Rainy",
"TEMPERATURE" => "Cool",
"HUMIDITY" => "Normal",
"WINDY" => "False",
"PLAY" => "Yes"
),
array(
"OUTLOOK" => "Rainy",
"TEMPERATURE" => "Cool",
"HUMIDITY" => "Normal",
"WINDY" => "True",
"PLAY" => "No"
),
array(
"OUTLOOK" => "Cloudy",
"TEMPERATURE" => "Cool",
"HUMIDITY" => "Normal",
"WINDY" => "True",
"PLAY" => "Yes"
),
array(
"OUTLOOK" => "Sunny",
"TEMPERATURE" => "Mild",
"HUMIDITY" => "High",
"WINDY" => "False",
"PLAY" => "No"
),
array(
"OUTLOOK" => "Sunny",
"TEMPERATURE" => "Cool",
"HUMIDITY" => "Normal",
"WINDY" => "False",
"PLAY" => "Yes"
),
array(
"OUTLOOK" => "Rainy",
"TEMPERATURE" => "Mild",
"HUMIDITY" => "Normal",
"WINDY" => "False",
"PLAY" => "Yes"
),
array(
"OUTLOOK" => "Sunny",
"TEMPERATURE" => "Mild",
"HUMIDITY" => "Normal",
"WINDY" => "True",
"PLAY" => "Yes"
),
array(
"OUTLOOK" => "Cloudy",
"TEMPERATURE" => "Mild",
"HUMIDITY" => "High",
"WINDY" => "True",
"PLAY" => "Yes"
),
array(
"OUTLOOK" => "Cloudy",
"TEMPERATURE" => "Hot",
"HUMIDITY" => "Normal",
"WINDY" => "False",
"PLAY" => "Yes"
),
array(
"OUTLOOK" => "Rainy",
"TEMPERATURE" => "Mild",
"HUMIDITY" => "High",
"WINDY" => "True",
"PLAY" => "No"
)
);

// Initialize Data
$input->setData($data); // Set data from array
$input->setAttributes(array('OUTLOOK', 'TEMPERATURE', 'HUMIDITY', 'WINDY', 'PLAY')); // Set attributes of data

// Initialize C4.5
$c45->c45 = $input; // Set input data
$c45->setTargetAttribute('PLAY'); // Set target attribute
$initialize = $c45->initialize(); // initialize

// Build Output
$buildTree = $initialize->buildTree(); // Build tree
$arrayTree = $buildTree->toArray(); // Set to array
$stringTree = $buildTree->toString(); // Set to string

echo "<pre>";
print_r ($arrayTree);
echo "</pre>";

echo $stringTree;
```

```php

$new_data = array(
Expand Down
Binary file modified example.xlsx
Binary file not shown.

0 comments on commit 91e369f

Please sign in to comment.