@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | /** |
| 133 | 133 | * @param array $records |
| 134 | - * @return DecisionTreeLeaf[] |
|
| 134 | + * @return null|DecisionTreeLeaf |
|
| 135 | 135 | */ |
| 136 | 136 | protected function getBestSplit($records) |
| 137 | 137 | { |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | |
| 255 | 255 | /** |
| 256 | 256 | * @param array $sample |
| 257 | - * @return mixed |
|
| 257 | + * @return string |
|
| 258 | 258 | */ |
| 259 | 259 | protected function predictSample(array $sample) |
| 260 | 260 | { |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Phpml\Classification; |
| 6 | 6 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | protected function getColumnTypes(array $samples) |
| 76 | 76 | { |
| 77 | 77 | $types = []; |
| 78 | - for ($i=0; $i<$this->featureCount; $i++) { |
|
| 78 | + for ($i = 0; $i < $this->featureCount; $i++) { |
|
| 79 | 79 | $values = array_column($samples, $i); |
| 80 | 80 | $isCategorical = $this->isCategoricalColumn($values); |
| 81 | 81 | $types[] = $isCategorical ? self::NOMINAL : self::CONTINUOS; |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | $this->actualDepth = $depth; |
| 96 | 96 | } |
| 97 | 97 | $leftRecords = []; |
| 98 | - $rightRecords= []; |
|
| 98 | + $rightRecords = []; |
|
| 99 | 99 | $remainingTargets = []; |
| 100 | 100 | $prevRecord = null; |
| 101 | 101 | $allSame = true; |
@@ -108,10 +108,10 @@ discard block |
||
| 108 | 108 | if ($split->evaluate($record)) { |
| 109 | 109 | $leftRecords[] = $recordNo; |
| 110 | 110 | } else { |
| 111 | - $rightRecords[]= $recordNo; |
|
| 111 | + $rightRecords[] = $recordNo; |
|
| 112 | 112 | } |
| 113 | 113 | $target = $this->targets[$recordNo]; |
| 114 | - if (! in_array($target, $remainingTargets)) { |
|
| 114 | + if (!in_array($target, $remainingTargets)) { |
|
| 115 | 115 | $remainingTargets[] = $target; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | $split->leftLeaf = $this->getSplitLeaf($leftRecords, $depth + 1); |
| 127 | 127 | } |
| 128 | 128 | if ($rightRecords) { |
| 129 | - $split->rightLeaf= $this->getSplitLeaf($rightRecords, $depth + 1); |
|
| 129 | + $split->rightLeaf = $this->getSplitLeaf($rightRecords, $depth + 1); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | return $split; |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | $samples = array_combine($records, $this->preprocess($samples)); |
| 144 | 144 | $bestGiniVal = 1; |
| 145 | 145 | $bestSplit = null; |
| 146 | - for ($i=0; $i<$this->featureCount; $i++) { |
|
| 146 | + for ($i = 0; $i < $this->featureCount; $i++) { |
|
| 147 | 147 | $colValues = []; |
| 148 | 148 | $baseValue = null; |
| 149 | 149 | foreach ($samples as $index => $row) { |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | $countMatrix[$label][$rowIndex]++; |
| 184 | 184 | } |
| 185 | 185 | $giniParts = [0, 0]; |
| 186 | - for ($i=0; $i<=1; $i++) { |
|
| 186 | + for ($i = 0; $i <= 1; $i++) { |
|
| 187 | 187 | $part = 0; |
| 188 | 188 | $sum = array_sum(array_column($countMatrix, $i)); |
| 189 | 189 | if ($sum > 0) { |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | // Detect and convert continuous data column values into |
| 206 | 206 | // discrete values by using the median as a threshold value |
| 207 | 207 | $columns = []; |
| 208 | - for ($i=0; $i<$this->featureCount; $i++) { |
|
| 208 | + for ($i = 0; $i < $this->featureCount; $i++) { |
|
| 209 | 209 | $values = array_column($samples, $i); |
| 210 | 210 | if ($this->columnTypes[$i] == self::CONTINUOS) { |
| 211 | 211 | $median = Mean::median($values); |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace Phpml\Classification\DecisionTree; |
| 5 | 5 | |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | /** |
| 25 | 25 | * @var DecisionTreeLeaf |
| 26 | 26 | */ |
| 27 | - public $rightLeaf= null; |
|
| 27 | + public $rightLeaf = null; |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * @var array |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | $recordField = $record[$this->columnIndex]; |
| 64 | 64 | if (preg_match("/^([<>=]{1,2})\s*(.*)/", $this->value, $matches)) { |
| 65 | 65 | $op = $matches[1]; |
| 66 | - $value= floatval($matches[2]); |
|
| 66 | + $value = floatval($matches[2]); |
|
| 67 | 67 | $recordField = strval($recordField); |
| 68 | 68 | eval("\$result = $recordField $op $value;"); |
| 69 | 69 | return $result; |
@@ -78,25 +78,25 @@ discard block |
||
| 78 | 78 | } else { |
| 79 | 79 | $value = $this->value; |
| 80 | 80 | $col = "col_$this->columnIndex"; |
| 81 | - if (! preg_match("/^[<>=]{1,2}/", $value)) { |
|
| 81 | + if (!preg_match("/^[<>=]{1,2}/", $value)) { |
|
| 82 | 82 | $value = "=$value"; |
| 83 | 83 | } |
| 84 | - $value = "<b>$col $value</b><br>Gini: ". number_format($this->giniIndex, 2); |
|
| 84 | + $value = "<b>$col $value</b><br>Gini: ".number_format($this->giniIndex, 2); |
|
| 85 | 85 | } |
| 86 | 86 | $str = "<table ><tr><td colspan=3 align=center style='border:1px solid;'> |
| 87 | 87 | $value</td></tr>"; |
| 88 | 88 | if ($this->leftLeaf || $this->rightLeaf) { |
| 89 | - $str .='<tr>'; |
|
| 89 | + $str .= '<tr>'; |
|
| 90 | 90 | if ($this->leftLeaf) { |
| 91 | - $str .="<td valign=top><b>| Yes</b><br>$this->leftLeaf</td>"; |
|
| 91 | + $str .= "<td valign=top><b>| Yes</b><br>$this->leftLeaf</td>"; |
|
| 92 | 92 | } else { |
| 93 | - $str .='<td></td>'; |
|
| 93 | + $str .= '<td></td>'; |
|
| 94 | 94 | } |
| 95 | - $str .='<td> </td>'; |
|
| 95 | + $str .= '<td> </td>'; |
|
| 96 | 96 | if ($this->rightLeaf) { |
| 97 | - $str .="<td valign=top align=right><b>No |</b><br>$this->rightLeaf</td>"; |
|
| 97 | + $str .= "<td valign=top align=right><b>No |</b><br>$this->rightLeaf</td>"; |
|
| 98 | 98 | } else { |
| 99 | - $str .='<td></td>'; |
|
| 99 | + $str .= '<td></td>'; |
|
| 100 | 100 | } |
| 101 | 101 | $str .= '</tr>'; |
| 102 | 102 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Phpml; |
| 6 | 6 | |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Phpml\CrossValidation; |
| 6 | 6 | |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Phpml\CrossValidation; |
| 6 | 6 | |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Phpml\SupportVectorMachine; |
| 6 | 6 | |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Phpml\SupportVectorMachine; |
| 6 | 6 | |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Phpml\SupportVectorMachine; |
| 6 | 6 | |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Phpml\Tokenization; |
| 6 | 6 | |