1 | <?php |
||
12 | class RandomForest extends Bagging |
||
13 | { |
||
14 | /** |
||
15 | * @var float|string |
||
16 | */ |
||
17 | protected $featureSubsetRatio = 'log'; |
||
18 | |||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $columnNames = null; |
||
23 | |||
24 | /** |
||
25 | * Initializes RandomForest with the given number of trees. More trees |
||
26 | * may increase the prediction performance while it will also substantially |
||
27 | * increase the processing time and the required memory |
||
28 | * |
||
29 | * @param type $numClassifier |
||
30 | */ |
||
31 | public function __construct($numClassifier = 50) |
||
37 | |||
38 | /** |
||
39 | * This method is used to determine how many of the original columns (features) |
||
40 | * will be used to construct subsets to train base classifiers.<br> |
||
41 | * |
||
42 | * Allowed values: 'sqrt', 'log' or any float number between 0.1 and 1.0 <br> |
||
43 | * |
||
44 | * Default value for the ratio is 'log' which results in log(numFeatures, 2) + 1 |
||
45 | * features to be taken into consideration while selecting subspace of features |
||
46 | * |
||
47 | * @param mixed $ratio string or float should be given |
||
48 | * @return $this |
||
49 | * @throws Exception |
||
50 | */ |
||
51 | public function setFeatureSubsetRatio($ratio) |
||
62 | |||
63 | /** |
||
64 | * RandomForest algorithm is usable *only* with DecisionTree |
||
65 | * |
||
66 | * @param string $classifier |
||
67 | * @param array $classifierOptions |
||
68 | * @return $this |
||
69 | */ |
||
70 | public function setClassifer(string $classifier, array $classifierOptions = []) |
||
78 | |||
79 | /** |
||
80 | * This will return an array including an importance value for |
||
81 | * each column in the given dataset. Importance values for a column |
||
82 | * is the average importance of that column in all trees in the forest |
||
83 | * |
||
84 | * @return array |
||
85 | */ |
||
86 | public function getFeatureImportances() |
||
113 | |||
114 | /** |
||
115 | * A string array to represent the columns is given. They are useful |
||
116 | * when trying to print some information about the trees such as feature importances |
||
117 | * |
||
118 | * @param array $names |
||
119 | * @return $this |
||
120 | */ |
||
121 | public function setColumnNames(array $names) |
||
127 | |||
128 | /** |
||
129 | * @param DecisionTree $classifier |
||
130 | * @param int $index |
||
131 | * @return DecisionTree |
||
132 | */ |
||
133 | protected function initSingleClassifier($classifier, $index) |
||
155 | } |
||
156 |