__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?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];
}
}
}
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| StopWords | Folder | 0777 |
|
|
| StopWords.php | File | 783 B | 0777 |
|
| TfIdfTransformer.php | File | 1.21 KB | 0777 |
|
| TokenCountVectorizer.php | File | 3.84 KB | 0777 |
|