Skip to content

Commit

Permalink
Use logger instead of echo
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdalpino committed Aug 7, 2020
1 parent 20fb26c commit e2cb304
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions train.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

ini_set('memory_limit', '-1');

$logger = new Screen();

$generator = new Agglomerate([
'red' => new Blob([255, 0, 0], 20.0),
'orange' => new Blob([255, 128, 0], 10.0),
Expand All @@ -27,13 +29,13 @@
'black' => new Blob([0, 0, 0], 10.0),
]);

$logger->info('Generating dataset');

[$training, $testing] = $generator->generate(5000)->stratifiedSplit(0.8);

$estimator = new KMeans(10);

$estimator->setLogger(new Screen());

echo 'Training ...' . PHP_EOL;
$estimator->setLogger($logger);

$estimator->train($training);

Expand All @@ -43,9 +45,9 @@
->toCSV(['losses'])
->write('progress.csv');

echo 'Progress saved to progress.csv' . PHP_EOL;
$logger->info('Progress saved to progress.csv');

echo 'Making predictions ...' . PHP_EOL;
$logger->info('Making predictions');

$predictions = $estimator->predict($testing);

Expand All @@ -57,10 +59,10 @@

$results->toJSON()->write('report.json');

echo 'Report saved to report.json' . PHP_EOL;
$logger->info('Report saved to report.json');

$metric = new Homogeneity();

$score = $metric->score($predictions, $testing->labels());

echo 'Clusters are ' . (string) round($score * 100.0, 2) . '% homogenous' . PHP_EOL;
$logger->info('Clusters are ' . (string) round($score * 100.0, 2) . '% homogenous');

0 comments on commit e2cb304

Please sign in to comment.