1 | <?php |
||
9 | trait OneVsRest |
||
10 | { |
||
11 | /** |
||
12 | * @var array |
||
13 | */ |
||
14 | protected $classifiers = []; |
||
15 | |||
16 | /** |
||
17 | * All provided training targets' labels. |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $allLabels = []; |
||
22 | |||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $costValues = []; |
||
27 | |||
28 | /** |
||
29 | * Train a binary classifier in the OvR style |
||
30 | */ |
||
31 | public function train(array $samples, array $targets): void |
||
38 | |||
39 | protected function trainByLabel(array $samples, array $targets, array $allLabels = []): void |
||
79 | |||
80 | /** |
||
81 | * Resets the classifier and the vars internally used by OneVsRest to create multiple classifiers. |
||
82 | */ |
||
83 | public function reset(): void |
||
91 | |||
92 | /** |
||
93 | * Returns an instance of the current class after cleaning up OneVsRest stuff. |
||
94 | * |
||
95 | * @return Classifier|OneVsRest |
||
96 | */ |
||
97 | protected function getClassifierCopy() |
||
107 | |||
108 | /** |
||
109 | * Groups all targets into two groups: Targets equal to |
||
110 | * the given label and the others |
||
111 | * |
||
112 | * $targets is not passed by reference nor contains objects so this method |
||
113 | * changes will not affect the caller $targets array. |
||
114 | * |
||
115 | * @param mixed $label |
||
116 | * |
||
117 | * @return array Binarized targets and target's labels |
||
118 | */ |
||
119 | private function binarizeTargets(array $targets, $label) : array |
||
130 | |||
131 | /** |
||
132 | * @return mixed |
||
133 | */ |
||
134 | protected function predictSample(array $sample) |
||
150 | |||
151 | /** |
||
152 | * Each classifier should implement this method instead of train(samples, targets) |
||
153 | */ |
||
154 | abstract protected function trainBinary(array $samples, array $targets, array $labels); |
||
155 | |||
156 | /** |
||
157 | * To be overwritten by OneVsRest classifiers. |
||
158 | * |
||
159 | * @return void |
||
160 | */ |
||
161 | abstract protected function resetBinary(): void; |
||
162 | |||
163 | /** |
||
164 | * Each classifier that make use of OvR approach should be able to |
||
165 | * return a probability for a sample to belong to the given label. |
||
166 | * |
||
167 | * @return mixed |
||
168 | */ |
||
169 | abstract protected function predictProbability(array $sample, string $label); |
||
170 | |||
171 | /** |
||
172 | * Each classifier should implement this method instead of predictSample() |
||
173 | * |
||
174 | * @return mixed |
||
175 | */ |
||
176 | abstract protected function predictSampleBinary(array $sample); |
||
177 | } |
||
178 |
This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.
The variable may have been renamed without also renaming all references.