This repository was archived by the owner on Dec 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.php
More file actions
47 lines (35 loc) · 1.44 KB
/
test.php
File metadata and controls
47 lines (35 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Phpml\Dataset\FilesDataset;
// $a = [];
// for ($i=0; $i < 500; $i++) {
// $new_dataset = [];
// $dataset = new FilesDataset(__DIR__ . '/app/Analysis/1mb');
// $labels = $dataset->getTargets();
// foreach($dataset->getSamples() as $key => $string)
// {
// $new_dataset[$key] = $string;
// }
// $time = microtime(true);
// $t = new \App\Analysis\TextAnalysis($new_dataset, $labels);
// $a[] = $t->train();
// }
// $average = array_sum($a) / count($a);
// // echo $average;
$new_dataset = [];
$dataset = new FilesDataset(__DIR__ . '/app/Analysis/1mb');
$labels = $dataset->getTargets();
foreach($dataset->getSamples() as $key => $string)
{
$new_dataset[$key] = $string;
}
$time = microtime(true); // time in Microseconds
$t = new \App\Analysis\TextAnalysis($new_dataset, $labels);
$t->train();
// echo 'Average Accuracy: ' . $average . PHP_EOL;
echo 'Train Time: ' . (microtime(true) - $time) . 's' . PHP_EOL;
echo 'AI Model Size: ' . strlen($t->export()) . PHP_EOL;
echo PHP_EOL . PHP_EOL . '----TESTS----' . PHP_EOL . PHP_EOL;
// var_dump($t->predict(["i am an american web developer that has a passion for coding"]), $t->predict(["this should not be flagged as spam"]));
echo collect($t->predict(["i am an american web developer that has a passion for coding"]))->flatten()->first() . PHP_EOL;
echo collect($t->predict(["this should not be flagged as spam"]))->flatten()->first() . PHP_EOL;