1414
1515ini_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 ),
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
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
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