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