-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPowerStationReport.php
45 lines (37 loc) · 1.25 KB
/
PowerStationReport.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
<?php
namespace App\Application\ML;
use App\Application\Path\AppPathResolver;
use App\Domain\FileNames;
use Rubix\ML\CrossValidation\Reports\AggregateReport;
use Rubix\ML\CrossValidation\Reports\ErrorAnalysis;
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/error-analysis.html
*/
readonly class PowerStationReport
{
public function __construct(
private AppPathResolver $appPathResolver,
) {
}
public function generateReport(): Report
{
$dataset = Labeled::fromIterator(new CSV(
$this->appPathResolver->getResourcesPath(FileNames::TEST_SET),
header: false,
))->transformLabels(fn ($value) => (float) $value);
$estimator = PersistentModel::load(new Filesystem(
$this->appPathResolver->getResourcesPath(FileNames::MODEL_FILENAME),
));
$predictions = $estimator->predict($dataset);
$report = new AggregateReport([
new ErrorAnalysis(),
]);
return $report->generate($predictions, $dataset->labels());
}
}