Skip to content

Commit 91e369f

Browse files
committed
update example of usage
1 parent 2c12d65 commit 91e369f

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

Readme.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,133 @@ print_r ($c45->buildTree()->toArray()); // print as array
7171
echo "</pre>";
7272
```
7373

74+
## Initialize Data from Array
75+
76+
```php
77+
$c45 = new Algorithm\C45();
78+
$input = new Algorithm\C45\DataInput;
79+
$data = array(
80+
array(
81+
"OUTLOOK" => "Sunny",
82+
"TEMPERATURE" => "Hot",
83+
"HUMIDITY" => "High",
84+
"WINDY" => "False",
85+
"PLAY" => "No"
86+
),
87+
array(
88+
"OUTLOOK" => "Sunny",
89+
"TEMPERATURE" => "Hot",
90+
"HUMIDITY" => "High",
91+
"WINDY" => "True",
92+
"PLAY" => "No"
93+
),
94+
array(
95+
"OUTLOOK" => "Cloudy",
96+
"TEMPERATURE" => "Hot",
97+
"HUMIDITY" => "High",
98+
"WINDY" => "False",
99+
"PLAY" => "Yes"
100+
),
101+
array(
102+
"OUTLOOK" => "Rainy",
103+
"TEMPERATURE" => "Mild",
104+
"HUMIDITY" => "High",
105+
"WINDY" => "False",
106+
"PLAY" => "Yes"
107+
),
108+
array(
109+
"OUTLOOK" => "Rainy",
110+
"TEMPERATURE" => "Cool",
111+
"HUMIDITY" => "Normal",
112+
"WINDY" => "False",
113+
"PLAY" => "Yes"
114+
),
115+
array(
116+
"OUTLOOK" => "Rainy",
117+
"TEMPERATURE" => "Cool",
118+
"HUMIDITY" => "Normal",
119+
"WINDY" => "True",
120+
"PLAY" => "No"
121+
),
122+
array(
123+
"OUTLOOK" => "Cloudy",
124+
"TEMPERATURE" => "Cool",
125+
"HUMIDITY" => "Normal",
126+
"WINDY" => "True",
127+
"PLAY" => "Yes"
128+
),
129+
array(
130+
"OUTLOOK" => "Sunny",
131+
"TEMPERATURE" => "Mild",
132+
"HUMIDITY" => "High",
133+
"WINDY" => "False",
134+
"PLAY" => "No"
135+
),
136+
array(
137+
"OUTLOOK" => "Sunny",
138+
"TEMPERATURE" => "Cool",
139+
"HUMIDITY" => "Normal",
140+
"WINDY" => "False",
141+
"PLAY" => "Yes"
142+
),
143+
array(
144+
"OUTLOOK" => "Rainy",
145+
"TEMPERATURE" => "Mild",
146+
"HUMIDITY" => "Normal",
147+
"WINDY" => "False",
148+
"PLAY" => "Yes"
149+
),
150+
array(
151+
"OUTLOOK" => "Sunny",
152+
"TEMPERATURE" => "Mild",
153+
"HUMIDITY" => "Normal",
154+
"WINDY" => "True",
155+
"PLAY" => "Yes"
156+
),
157+
array(
158+
"OUTLOOK" => "Cloudy",
159+
"TEMPERATURE" => "Mild",
160+
"HUMIDITY" => "High",
161+
"WINDY" => "True",
162+
"PLAY" => "Yes"
163+
),
164+
array(
165+
"OUTLOOK" => "Cloudy",
166+
"TEMPERATURE" => "Hot",
167+
"HUMIDITY" => "Normal",
168+
"WINDY" => "False",
169+
"PLAY" => "Yes"
170+
),
171+
array(
172+
"OUTLOOK" => "Rainy",
173+
"TEMPERATURE" => "Mild",
174+
"HUMIDITY" => "High",
175+
"WINDY" => "True",
176+
"PLAY" => "No"
177+
)
178+
);
179+
180+
// Initialize Data
181+
$input->setData($data); // Set data from array
182+
$input->setAttributes(array('OUTLOOK', 'TEMPERATURE', 'HUMIDITY', 'WINDY', 'PLAY')); // Set attributes of data
183+
184+
// Initialize C4.5
185+
$c45->c45 = $input; // Set input data
186+
$c45->setTargetAttribute('PLAY'); // Set target attribute
187+
$initialize = $c45->initialize(); // initialize
188+
189+
// Build Output
190+
$buildTree = $initialize->buildTree(); // Build tree
191+
$arrayTree = $buildTree->toArray(); // Set to array
192+
$stringTree = $buildTree->toString(); // Set to string
193+
194+
echo "<pre>";
195+
print_r ($arrayTree);
196+
echo "</pre>";
197+
198+
echo $stringTree;
199+
```
200+
74201
```php
75202

76203
$new_data = array(

example.xlsx

881 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)