mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-24 22:07:33 +00:00
Short syntax for applied operations
This commit is contained in:
parent
df28656d0d
commit
a4f65bd13f
@ -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)
|
||||
{
|
||||
|
@ -173,8 +173,6 @@ class TokenCountVectorizer implements Transformer
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function checkDocumentFrequency(array &$samples)
|
||||
{
|
||||
|
@ -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));
|
||||
|
@ -31,7 +31,7 @@ class Accuracy
|
||||
}
|
||||
|
||||
if ($normalize) {
|
||||
$score = $score / count($actualLabels);
|
||||
$score /= count($actualLabels);
|
||||
}
|
||||
|
||||
return $score;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user