Completed
Pull Request — master (#49)
by Povilas
03:08
created
src/Phpml/ModelManager.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace Phpml;
6 6
 
Please login to merge, or discard this patch.
src/Phpml/Classification/DecisionTree.php 1 patch
Spacing   +8 added lines, -8 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
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
     protected function getColumnTypes(array $samples)
82 82
     {
83 83
         $types = [];
84
-        for ($i=0; $i<$this->featureCount; $i++) {
84
+        for ($i = 0; $i < $this->featureCount; $i++) {
85 85
             $values = array_column($samples, $i);
86 86
             $isCategorical = $this->isCategoricalColumn($values);
87 87
             $types[] = $isCategorical ? self::NOMINAL : self::CONTINUOS;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
             $this->actualDepth = $depth;
102 102
         }
103 103
         $leftRecords = [];
104
-        $rightRecords= [];
104
+        $rightRecords = [];
105 105
         $remainingTargets = [];
106 106
         $prevRecord = null;
107 107
         $allSame = true;
@@ -114,10 +114,10 @@  discard block
 block discarded – undo
114 114
             if ($split->evaluate($record)) {
115 115
                 $leftRecords[] = $recordNo;
116 116
             } else {
117
-                $rightRecords[]= $recordNo;
117
+                $rightRecords[] = $recordNo;
118 118
             }
119 119
             $target = $this->targets[$recordNo];
120
-            if (! in_array($target, $remainingTargets)) {
120
+            if (!in_array($target, $remainingTargets)) {
121 121
                 $remainingTargets[] = $target;
122 122
             }
123 123
         }
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
                 $split->leftLeaf = $this->getSplitLeaf($leftRecords, $depth + 1);
133 133
             }
134 134
             if ($rightRecords) {
135
-                $split->rightLeaf= $this->getSplitLeaf($rightRecords, $depth + 1);
135
+                $split->rightLeaf = $this->getSplitLeaf($rightRecords, $depth + 1);
136 136
             }
137 137
         }
138 138
         return $split;
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
             $countMatrix[$label][$rowIndex]++;
211 211
         }
212 212
         $giniParts = [0, 0];
213
-        for ($i=0; $i<=1; $i++) {
213
+        for ($i = 0; $i <= 1; $i++) {
214 214
             $part = 0;
215 215
             $sum = array_sum(array_column($countMatrix, $i));
216 216
             if ($sum > 0) {
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
         // Detect and convert continuous data column values into
233 233
         // discrete values by using the median as a threshold value
234 234
         $columns = [];
235
-        for ($i=0; $i<$this->featureCount; $i++) {
235
+        for ($i = 0; $i < $this->featureCount; $i++) {
236 236
             $values = array_column($samples, $i);
237 237
             if ($this->columnTypes[$i] == self::CONTINUOS) {
238 238
                 $median = Mean::median($values);
Please login to merge, or discard this patch.
src/Phpml/Classification/Ensemble/RandomForest.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Phpml\Classification\Ensemble;
5 5
 
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
     protected function initSingleClassifier($classifier, $index)
71 71
     {
72 72
         if (is_float($this->featureSubsetRatio)) {
73
-            $featureCount = (int)($this->featureSubsetRatio * $this->featureCount);
73
+            $featureCount = (int) ($this->featureSubsetRatio * $this->featureCount);
74 74
         } elseif ($this->featureCount == 'sqrt') {
75
-            $featureCount = (int)sqrt($this->featureCount) + 1;
75
+            $featureCount = (int) sqrt($this->featureCount) + 1;
76 76
         } else {
77
-            $featureCount = (int)log($this->featureCount, 2) + 1;
77
+            $featureCount = (int) log($this->featureCount, 2) + 1;
78 78
         }
79 79
 
80 80
         if ($featureCount >= $this->featureCount) {
Please login to merge, or discard this patch.
src/Phpml/Classification/DecisionTree/DecisionTreeLeaf.php 1 patch
Spacing   +14 added lines, -14 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\DecisionTree;
6 6
 
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
     /**
25 25
      * @var DecisionTreeLeaf
26 26
      */
27
-    public $rightLeaf= null;
27
+    public $rightLeaf = null;
28 28
 
29 29
     /**
30 30
      * @var array
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
         $recordField = $record[$this->columnIndex];
69 69
         if ($this->isContinuous && preg_match("/^([<>=]{1,2})\s*(.*)/", strval($this->value), $matches)) {
70 70
             $op = $matches[1];
71
-            $value= floatval($matches[2]);
71
+            $value = floatval($matches[2]);
72 72
             $recordField = strval($recordField);
73 73
             eval("\$result = $recordField $op $value;");
74 74
             return $result;
@@ -88,16 +88,16 @@  discard block
 block discarded – undo
88 88
             return 0.0;
89 89
         }
90 90
 
91
-        $nodeSampleCount = (float)count($this->records);
91
+        $nodeSampleCount = (float) count($this->records);
92 92
         $iT = $this->giniIndex;
93 93
 
94 94
         if ($this->leftLeaf) {
95
-            $pL = count($this->leftLeaf->records)/$nodeSampleCount;
95
+            $pL = count($this->leftLeaf->records) / $nodeSampleCount;
96 96
             $iT -= $pL * $this->leftLeaf->giniIndex;
97 97
         }
98 98
 
99 99
         if ($this->rightLeaf) {
100
-            $pR = count($this->rightLeaf->records)/$nodeSampleCount;
100
+            $pR = count($this->rightLeaf->records) / $nodeSampleCount;
101 101
             $iT -= $pR * $this->rightLeaf->giniIndex;
102 102
         }
103 103
 
@@ -121,25 +121,25 @@  discard block
 block discarded – undo
121 121
             } else {
122 122
                 $col = "col_$this->columnIndex";
123 123
             }
124
-            if (! preg_match("/^[<>=]{1,2}/", $value)) {
124
+            if (!preg_match("/^[<>=]{1,2}/", $value)) {
125 125
                 $value = "=$value";
126 126
             }
127
-            $value = "<b>$col $value</b><br>Gini: ". number_format($this->giniIndex, 2);
127
+            $value = "<b>$col $value</b><br>Gini: ".number_format($this->giniIndex, 2);
128 128
         }
129 129
         $str = "<table ><tr><td colspan=3 align=center style='border:1px solid;'>
130 130
 				$value</td></tr>";
131 131
         if ($this->leftLeaf || $this->rightLeaf) {
132
-            $str .='<tr>';
132
+            $str .= '<tr>';
133 133
             if ($this->leftLeaf) {
134
-                $str .="<td valign=top><b>| Yes</b><br>" . $this->leftLeaf->getHTML($columnNames) . "</td>";
134
+                $str .= "<td valign=top><b>| Yes</b><br>".$this->leftLeaf->getHTML($columnNames)."</td>";
135 135
             } else {
136
-                $str .='<td></td>';
136
+                $str .= '<td></td>';
137 137
             }
138
-            $str .='<td>&nbsp;</td>';
138
+            $str .= '<td>&nbsp;</td>';
139 139
             if ($this->rightLeaf) {
140
-                $str .="<td valign=top align=right><b>No |</b><br>" . $this->rightLeaf->getHTML($columnNames) . "</td>";
140
+                $str .= "<td valign=top align=right><b>No |</b><br>".$this->rightLeaf->getHTML($columnNames)."</td>";
141 141
             } else {
142
-                $str .='<td></td>';
142
+                $str .= '<td></td>';
143 143
             }
144 144
             $str .= '</tr>';
145 145
         }
Please login to merge, or discard this patch.
src/Phpml/Classification/Ensemble/Bagging.php 1 patch
Spacing   +3 added lines, -3 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
 
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
         $targets = [];
141 141
         srand($index);
142 142
         $bootstrapSize = $this->subsetRatio * $this->numSamples;
143
-        for ($i=0; $i < $bootstrapSize; $i++) {
143
+        for ($i = 0; $i < $bootstrapSize; $i++) {
144 144
             $rand = rand(0, $this->numSamples - 1);
145 145
             $samples[] = $this->samples[$rand];
146 146
             $targets[] = $this->targets[$rand];
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
     protected function initClassifiers()
155 155
     {
156 156
         $classifiers = [];
157
-        for ($i=0; $i<$this->numClassifier; $i++) {
157
+        for ($i = 0; $i < $this->numClassifier; $i++) {
158 158
             $ref = new \ReflectionClass($this->classifier);
159 159
             if ($this->classifierOptions) {
160 160
                 $obj = $ref->newInstanceArgs($this->classifierOptions);
Please login to merge, or discard this patch.