mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-28 15:56:36 +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 ($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)
|
||||||
{
|
{
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -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));
|
||||||
|
@ -31,7 +31,7 @@ class Accuracy
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($normalize) {
|
if ($normalize) {
|
||||||
$score = $score / count($actualLabels);
|
$score /= count($actualLabels);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $score;
|
return $score;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user