-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpamModelReport.php
49 lines (41 loc) · 1.44 KB
/
SpamModelReport.php
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
48
49
<?php
namespace App\Module\ML\Application\Model;
use App\Core\Application\Path\AppPathResolver;
use Rubix\ML\CrossValidation\Reports\AggregateReport;
use Rubix\ML\CrossValidation\Reports\ConfusionMatrix;
use Rubix\ML\CrossValidation\Reports\MulticlassBreakdown;
use Rubix\ML\Datasets\Labeled;
use Rubix\ML\Extractors\CSV;
use Rubix\ML\PersistentModel;
use Rubix\ML\Persisters\Filesystem;
use Rubix\ML\Report;
/**
* @see https://docs.rubixml.com/latest/cross-validation.html
* @see https://docs.rubixml.com/latest/cross-validation/reports/multiclass-breakdown.html
* @see https://docs.rubixml.com/latest/cross-validation/reports/confusion-matrix.html
*/
readonly class SpamModelReport
{
public function __construct(
private AppPathResolver $appPathResolver,
) {
}
public function generateReport(
string $testingDatasetFilename,
string $modelFilename,
): Report {
$dataset = Labeled::fromIterator(new CSV(
$this->appPathResolver->getDatasetPath($testingDatasetFilename),
header: true,
));
$estimator = PersistentModel::load(new Filesystem(
$this->appPathResolver->getModelPath($modelFilename)
));
$predictions = $estimator->predict($dataset);
$report = new AggregateReport([
new MulticlassBreakdown(),
new ConfusionMatrix(),
]);
return $report->generate($predictions, $dataset->labels());
}
}