Test Failed
Push — master ( e8c600...c028a7 )
by Arkadiusz
02:50
created
src/Phpml/Classification/WeightedClassifier.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@
 block discarded – undo
1
-<?php declare(strict_types=1);
1
+<?php declare(strict_types = 1);
2 2
 
3 3
 namespace Phpml\Classification;
4 4
 
Please login to merge, or discard this patch.
src/Phpml/Classification/DecisionTree.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace Phpml\Classification;
6 6
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
     {
115 115
         $types = [];
116 116
         $featureCount = count($samples[0]);
117
-        for ($i=0; $i < $featureCount; $i++) {
117
+        for ($i = 0; $i < $featureCount; $i++) {
118 118
             $values = array_column($samples, $i);
119 119
             $isCategorical = self::isCategoricalColumn($values);
120 120
             $types[] = $isCategorical ? self::NOMINAL : self::CONTINUOS;
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
         // otherwise group the records so that we can classify the leaf
139 139
         // in case maximum depth is reached
140 140
         $leftRecords = [];
141
-        $rightRecords= [];
141
+        $rightRecords = [];
142 142
         $remainingTargets = [];
143 143
         $prevRecord = null;
144 144
         $allSame = true;
@@ -156,12 +156,12 @@  discard block
 block discarded – undo
156 156
             if ($split->evaluate($record)) {
157 157
                 $leftRecords[] = $recordNo;
158 158
             } else {
159
-                $rightRecords[]= $recordNo;
159
+                $rightRecords[] = $recordNo;
160 160
             }
161 161
 
162 162
             // Group remaining targets
163 163
             $target = $this->targets[$recordNo];
164
-            if (! array_key_exists($target, $remainingTargets)) {
164
+            if (!array_key_exists($target, $remainingTargets)) {
165 165
                 $remainingTargets[$target] = 1;
166 166
             } else {
167 167
                 $remainingTargets[$target]++;
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
                 $split->leftLeaf = $this->getSplitLeaf($leftRecords, $depth + 1);
178 178
             }
179 179
             if ($rightRecords) {
180
-                $split->rightLeaf= $this->getSplitLeaf($rightRecords, $depth + 1);
180
+                $split->rightLeaf = $this->getSplitLeaf($rightRecords, $depth + 1);
181 181
             }
182 182
         }
183 183
         return $split;
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
     protected function getSelectedFeatures()
248 248
     {
249 249
         $allFeatures = range(0, $this->featureCount - 1);
250
-        if ($this->numUsableFeatures == 0 && ! $this->selectedFeatures) {
250
+        if ($this->numUsableFeatures == 0 && !$this->selectedFeatures) {
251 251
             return $allFeatures;
252 252
         }
253 253
 
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
             $countMatrix[$label][$rowIndex]++;
284 284
         }
285 285
         $giniParts = [0, 0];
286
-        for ($i=0; $i<=1; $i++) {
286
+        for ($i = 0; $i <= 1; $i++) {
287 287
             $part = 0;
288 288
             $sum = array_sum(array_column($countMatrix, $i));
289 289
             if ($sum > 0) {
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
         // Detect and convert continuous data column values into
306 306
         // discrete values by using the median as a threshold value
307 307
         $columns = [];
308
-        for ($i=0; $i<$this->featureCount; $i++) {
308
+        for ($i = 0; $i < $this->featureCount; $i++) {
309 309
             $values = array_column($samples, $i);
310 310
             if ($this->columnTypes[$i] == self::CONTINUOS) {
311 311
                 $median = Mean::median($values);
Please login to merge, or discard this patch.
src/Phpml/Classification/Linear/Perceptron.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace Phpml\Classification\Linear;
6 6
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
                 // Update bias
170 170
                 $this->weights[0] += $update * $this->learningRate; // Bias
171 171
                 // Update other weights
172
-                for ($i=1; $i <= $this->featureCount; $i++) {
172
+                for ($i = 1; $i <= $this->featureCount; $i++) {
173 173
                     $this->weights[$i] += $update * $sample[$i - 1] * $this->learningRate;
174 174
                 }
175 175
             }
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
     {
203 203
         // Check for early stop: No change larger than 1e-5
204 204
         $diff = array_map(
205
-            function ($w1, $w2) {
205
+            function($w1, $w2) {
206 206
                 return abs($w1 - $w2) > 1e-5 ? 1 : 0;
207 207
             },
208 208
             $oldWeights, $this->weights);
@@ -259,6 +259,6 @@  discard block
 block discarded – undo
259 259
 
260 260
         $predictedClass = $this->outputClass($sample);
261 261
 
262
-        return $this->labels[ $predictedClass ];
262
+        return $this->labels[$predictedClass];
263 263
     }
264 264
 }
Please login to merge, or discard this patch.
src/Phpml/Classification/Linear/DecisionStump.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace Phpml\Classification\Linear;
6 6
 
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
         $labels = array_count_values($this->targets);
84 84
         $this->labels = array_keys($labels);
85 85
         if (count($this->labels) != 2) {
86
-            throw new \Exception("DecisionStump can classify between two classes only:" . implode(',', $this->labels));
86
+            throw new \Exception("DecisionStump can classify between two classes only:".implode(',', $this->labels));
87 87
         }
88 88
 
89 89
         // If a column index is given, it should be among the existing columns
@@ -160,8 +160,8 @@  discard block
 block discarded – undo
160 160
             }
161 161
 
162 162
             // Try other possible points one by one
163
-            for ($step = $minValue; $step <= $maxValue; $step+= $stepSize) {
164
-                $threshold = (float)$step;
163
+            for ($step = $minValue; $step <= $maxValue; $step += $stepSize) {
164
+                $threshold = (float) $step;
165 165
                 $errorRate = $this->calculateErrorRate($threshold, $operator, $values);
166 166
                 if ($errorRate < $split['trainingErrorRate']) {
167 167
                     $split = ['value' => $threshold, 'operator' => $operator,
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
     {
184 184
         $values = array_column($this->samples, $col);
185 185
         $valueCounts = array_count_values($values);
186
-        $distinctVals= array_keys($valueCounts);
186
+        $distinctVals = array_keys($valueCounts);
187 187
 
188 188
         $split = null;
189 189
 
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
         $total = (float) array_sum($this->weights);
239 239
         $wrong = 0.0;
240 240
         $leftLabel = $this->labels[0];
241
-        $rightLabel= $this->labels[1];
241
+        $rightLabel = $this->labels[1];
242 242
         foreach ($values as $index => $value) {
243 243
             if ($this->evaluate($threshold, $operator, $value)) {
244 244
                 $predicted = $leftLabel;
Please login to merge, or discard this patch.
src/Phpml/Classification/Ensemble/AdaBoost.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace Phpml\Classification\Ensemble;
6 6
 
@@ -173,15 +173,15 @@  discard block
 block discarded – undo
173 173
     {
174 174
         $weights = $this->weights;
175 175
         $std = StandardDeviation::population($weights);
176
-        $mean= Mean::arithmetic($weights);
176
+        $mean = Mean::arithmetic($weights);
177 177
         $min = min($weights);
178
-        $minZ= (int)round(($min - $mean) / $std);
178
+        $minZ = (int) round(($min - $mean) / $std);
179 179
 
180 180
         $samples = [];
181 181
         $targets = [];
182 182
         foreach ($weights as $index => $weight) {
183
-            $z = (int)round(($weight - $mean) / $std) - $minZ + 1;
184
-            for ($i=0; $i < $z; $i++) {
183
+            $z = (int) round(($weight - $mean) / $std) - $minZ + 1;
184
+            for ($i = 0; $i < $z; $i++) {
185 185
                 if (rand(0, 1) == 0) {
186 186
                     continue;
187 187
                 }
@@ -260,6 +260,6 @@  discard block
 block discarded – undo
260 260
             $sum += $h * $alpha;
261 261
         }
262 262
 
263
-        return $this->labels[ $sum > 0 ? 1 : -1];
263
+        return $this->labels[$sum > 0 ? 1 : -1];
264 264
     }
265 265
 }
Please login to merge, or discard this patch.