Skip to content

Commit

Permalink
Short syntax for applied operations
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas committed Dec 12, 2016
1 parent df28656 commit a4f65bd
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 11 deletions.
4 changes: 1 addition & 3 deletions src/Phpml/FeatureExtraction/TfIdfTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ public function transform(array &$samples)
{
foreach ($samples as &$sample) {
foreach ($sample as $index => &$feature) {
$feature = $feature * $this->idf[$index];
$feature *= $this->idf[$index];
}
}
}

/**
* @param array $samples
*
* @return array
*/
private function countTokensFrequency(array $samples)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Phpml/FeatureExtraction/TokenCountVectorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ private function updateFrequency(string $token)

/**
* @param array $samples
*
* @return array
*/
private function checkDocumentFrequency(array &$samples)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Phpml/Math/Statistic/Correlation.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public static function pearson(array $x, array $y)
for ($i = 0; $i < $count; ++$i) {
$a = $x[$i] - $meanX;
$b = $y[$i] - $meanY;
$axb = $axb + ($a * $b);
$a2 = $a2 + pow($a, 2);
$b2 = $b2 + pow($b, 2);
$axb += ($a * $b);
$a2 += pow($a, 2);
$b2 += pow($b, 2);
}

$corr = $axb / sqrt((float) ($a2 * $b2));
Expand Down
2 changes: 1 addition & 1 deletion src/Phpml/Metric/Accuracy.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function score(array $actualLabels, array $predictedLabels, bool $
}

if ($normalize) {
$score = $score / count($actualLabels);
$score /= count($actualLabels);
}

return $score;
Expand Down
4 changes: 2 additions & 2 deletions src/Phpml/Preprocessing/Normalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private function normalizeL1(array &$sample)
$sample = array_fill(0, $count, 1.0 / $count);
} else {
foreach ($sample as &$feature) {
$feature = $feature / $norm1;
$feature /= $norm1;
}
}
}
Expand All @@ -84,7 +84,7 @@ private function normalizeL2(array &$sample)
$sample = array_fill(0, count($sample), 1);
} else {
foreach ($sample as &$feature) {
$feature = $feature / $norm2;
$feature /= $norm2;
}
}
}
Expand Down

0 comments on commit a4f65bd

Please sign in to comment.