Skip to content

Commit e2cb304

Browse files
committed
Use logger instead of echo
1 parent 20fb26c commit e2cb304

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

train.php

+9-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

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

17+
$logger = new Screen();
18+
1719
$generator = new Agglomerate([
1820
'red' => new Blob([255, 0, 0], 20.0),
1921
'orange' => new Blob([255, 128, 0], 10.0),
@@ -27,13 +29,13 @@
2729
'black' => new Blob([0, 0, 0], 10.0),
2830
]);
2931

32+
$logger->info('Generating dataset');
33+
3034
[$training, $testing] = $generator->generate(5000)->stratifiedSplit(0.8);
3135

3236
$estimator = new KMeans(10);
3337

34-
$estimator->setLogger(new Screen());
35-
36-
echo 'Training ...' . PHP_EOL;
38+
$estimator->setLogger($logger);
3739

3840
$estimator->train($training);
3941

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

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

48-
echo 'Making predictions ...' . PHP_EOL;
50+
$logger->info('Making predictions');
4951

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

@@ -57,10 +59,10 @@
5759

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

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

6264
$metric = new Homogeneity();
6365

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

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

0 commit comments

Comments
 (0)