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 ($sample as $index => &$feature) {
$feature = $feature * $this->idf[$index];
$feature *= $this->idf[$index];
}
}
}
/**
* @param array $samples
*
* @return array
*/
private function countTokensFrequency(array $samples)
{

View File

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

View File

@ -33,9 +33,9 @@ class Correlation
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));

View File

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

View File

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