src/Phpml/Classification/Ensemble/AdaBoost.php 1 location
|
@@ 184-190 (lines=7) @@
|
| 181 |
|
$targets = []; |
| 182 |
|
foreach ($weights as $index => $weight) { |
| 183 |
|
$z = (int)round(($weight - $mean) / $std) - $minZ + 1; |
| 184 |
|
for ($i=0; $i < $z; $i++) { |
| 185 |
|
if (rand(0, 1) == 0) { |
| 186 |
|
continue; |
| 187 |
|
} |
| 188 |
|
$samples[] = $this->samples[$index]; |
| 189 |
|
$targets[] = $this->targets[$index]; |
| 190 |
|
} |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
return [$samples, $targets]; |
src/Phpml/Classification/Ensemble/Bagging.php 1 location
|
@@ 143-147 (lines=5) @@
|
| 140 |
|
$targets = []; |
| 141 |
|
srand($index); |
| 142 |
|
$bootstrapSize = $this->subsetRatio * $this->numSamples; |
| 143 |
|
for ($i=0; $i < $bootstrapSize; $i++) { |
| 144 |
|
$rand = rand(0, $this->numSamples - 1); |
| 145 |
|
$samples[] = $this->samples[$rand]; |
| 146 |
|
$targets[] = $this->targets[$rand]; |
| 147 |
|
} |
| 148 |
|
return [$samples, $targets]; |
| 149 |
|
} |
| 150 |
|
|