Short syntax for applied operations

This commit is contained in:
Arkadiusz Kondas 2016-12-12 18:34:20 +01:00
parent df28656d0d
commit a4f65bd13f
5 changed files with 7 additions and 11 deletions

View File

@ -43,15 +43,13 @@ class TfIdfTransformer implements Transformer
{ {
foreach ($samples as &$sample) { foreach ($samples as &$sample) {
foreach ($sample as $index => &$feature) { foreach ($sample as $index => &$feature) {
$feature = $feature * $this->idf[$index]; $feature *= $this->idf[$index];
} }
} }
} }
/** /**
* @param array $samples * @param array $samples
*
* @return array
*/ */
private function countTokensFrequency(array $samples) private function countTokensFrequency(array $samples)
{ {

View File

@ -173,8 +173,6 @@ class TokenCountVectorizer implements Transformer
/** /**
* @param array $samples * @param array $samples
*
* @return array
*/ */
private function checkDocumentFrequency(array &$samples) private function checkDocumentFrequency(array &$samples)
{ {

View File

@ -33,9 +33,9 @@ class Correlation
for ($i = 0; $i < $count; ++$i) { for ($i = 0; $i < $count; ++$i) {
$a = $x[$i] - $meanX; $a = $x[$i] - $meanX;
$b = $y[$i] - $meanY; $b = $y[$i] - $meanY;
$axb = $axb + ($a * $b); $axb += ($a * $b);
$a2 = $a2 + pow($a, 2); $a2 += pow($a, 2);
$b2 = $b2 + pow($b, 2); $b2 += pow($b, 2);
} }
$corr = $axb / sqrt((float) ($a2 * $b2)); $corr = $axb / sqrt((float) ($a2 * $b2));

View File

@ -31,7 +31,7 @@ class Accuracy
} }
if ($normalize) { if ($normalize) {
$score = $score / count($actualLabels); $score /= count($actualLabels);
} }
return $score; return $score;

View File

@ -64,7 +64,7 @@ class Normalizer implements Preprocessor
$sample = array_fill(0, $count, 1.0 / $count); $sample = array_fill(0, $count, 1.0 / $count);
} else { } else {
foreach ($sample as &$feature) { foreach ($sample as &$feature) {
$feature = $feature / $norm1; $feature /= $norm1;
} }
} }
} }
@ -84,7 +84,7 @@ class Normalizer implements Preprocessor
$sample = array_fill(0, count($sample), 1); $sample = array_fill(0, count($sample), 1);
} else { } else {
foreach ($sample as &$feature) { foreach ($sample as &$feature) {
$feature = $feature / $norm2; $feature /= $norm2;
} }
} }
} }