���ѧۧݧ�ӧ�� �ާ֧ߧ֧էا֧� - ���֧էѧܧ�ڧ��ӧѧ�� - /home3/cpr76684/public_html/Aem/lib/mlbackend/php/phpml/src/Phpml/FeatureExtraction/TfIdfTransformer.php
���ѧ٧ѧ�
<?php declare(strict_types=1); namespace Phpml\FeatureExtraction; use Phpml\Transformer; class TfIdfTransformer implements Transformer { /** * @var array */ private $idf = []; public function __construct(array $samples = []) { if (count($samples) > 0) { $this->fit($samples); } } public function fit(array $samples, ?array $targets = null): void { $this->countTokensFrequency($samples); $count = count($samples); foreach ($this->idf as &$value) { $value = log((float) ($count / $value), 10.0); } } public function transform(array &$samples, ?array &$targets = null): void { foreach ($samples as &$sample) { foreach ($sample as $index => &$feature) { $feature *= $this->idf[$index]; } } } private function countTokensFrequency(array $samples): void { $this->idf = array_fill_keys(array_keys($samples[0]), 0); foreach ($samples as $sample) { foreach ($sample as $index => $count) { if ($count > 0) { ++$this->idf[$index]; } } } } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | ���֧ߧ֧�ѧ�ڧ� ����ѧߧڧ��: 0 |
proxy
|
phpinfo
|
���ѧ����ۧܧ�