forked from kokukuma/php-decision-tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.php
49 lines (38 loc) · 2.35 KB
/
sample.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
require_once('Make_Decision_Tree.php');
// 渡すデータ構造
$data = array();
$data[0] = array("生死"=>"生還","年齢"=>"35","性別"=>"男","等級"=>"1等");
$data[1] = array("生死"=>"生還","年齢"=>"12","性別"=>"女","等級"=>"1等");
$data[2] = array("生死"=>"生還","年齢"=>"35","性別"=>"女","等級"=>"1等");
$data[3] = array("生死"=>"死亡","年齢"=>"26","性別"=>"男","等級"=>"1等");
$data[4] = array("生死"=>"生還","年齢"=>"23","性別"=>"女","等級"=>"1等");
$data[5] = array("生死"=>"死亡","年齢"=>"31","性別"=>"男","等級"=>"2等");
$data[6] = array("生死"=>"生還","年齢"=>"32","性別"=>"男","等級"=>"2等");
$data[7] = array("生死"=>"生還","年齢"=>"23","性別"=>"男","等級"=>"2等");
$data[8] = array("生死"=>"死亡","年齢"=>"25","性別"=>"男","等級"=>"2等");
$data[9] = array("生死"=>"死亡","年齢"=>"29","性別"=>"女","等級"=>"2等");
$data[10] = array("生死"=>"生還","年齢"=>"40","性別"=>"女","等級"=>"2等");
$data[11] = array("生死"=>"生還","年齢"=>"12","性別"=>"女","等級"=>"2等");
$data[12] = array("生死"=>"生還","年齢"=>"35","性別"=>"女","等級"=>"2等");
$data[13] = array("生死"=>"死亡","年齢"=>"34","性別"=>"男","等級"=>"3等");
$data[14] = array("生死"=>"生還","年齢"=>"23","性別"=>"女","等級"=>"3等");
$data[15] = array("生死"=>"死亡","年齢"=>"31","性別"=>"男","等級"=>"3等");
$data[16] = array("生死"=>"死亡","年齢"=>"32","性別"=>"男","等級"=>"3等");
$data[17] = array("生死"=>"死亡","年齢"=>"23","性別"=>"男","等級"=>"乗組員");
$data[18] = array("生死"=>"死亡","年齢"=>"25","性別"=>"男","等級"=>"乗組員");
$data[19] = array("生死"=>"死亡","年齢"=>"29","性別"=>"女","等級"=>"乗組員");
$data[20] = array("生死"=>"生還","年齢"=>"40","性別"=>"女","等級"=>"乗組員");
// データの引き渡し
$dt = new Decision_Tree($data);
//木の生成(分類木)
$tree = $dt->classify('生死','生還','死亡');
echo "-------- Decision_Tree\n";
var_dump($tree);
//ルールの使用方法
$target = array("年齢"=>"40","性別"=>"男","等級"=>"2等");
$res = $dt->prognosis($target);
$res = $dt->exe_prognosis($tree,$target);
echo "-------- estimate\n";
var_dump($res);
?>