14
14
15
15
ini_set ('memory_limit ' , '-1 ' );
16
16
17
+ $ logger = new Screen ();
18
+
17
19
$ generator = new Agglomerate ([
18
20
'red ' => new Blob ([255 , 0 , 0 ], 20.0 ),
19
21
'orange ' => new Blob ([255 , 128 , 0 ], 10.0 ),
27
29
'black ' => new Blob ([0 , 0 , 0 ], 10.0 ),
28
30
]);
29
31
32
+ $ logger ->info ('Generating dataset ' );
33
+
30
34
[$ training , $ testing ] = $ generator ->generate (5000 )->stratifiedSplit (0.8 );
31
35
32
36
$ estimator = new KMeans (10 );
33
37
34
- $ estimator ->setLogger (new Screen ());
35
-
36
- echo 'Training ... ' . PHP_EOL ;
38
+ $ estimator ->setLogger ($ logger );
37
39
38
40
$ estimator ->train ($ training );
39
41
43
45
->toCSV (['losses ' ])
44
46
->write ('progress.csv ' );
45
47
46
- echo 'Progress saved to progress.csv ' . PHP_EOL ;
48
+ $ logger -> info ( 'Progress saved to progress.csv ' ) ;
47
49
48
- echo 'Making predictions ... ' . PHP_EOL ;
50
+ $ logger -> info ( 'Making predictions ' ) ;
49
51
50
52
$ predictions = $ estimator ->predict ($ testing );
51
53
57
59
58
60
$ results ->toJSON ()->write ('report.json ' );
59
61
60
- echo 'Report saved to report.json ' . PHP_EOL ;
62
+ $ logger -> info ( 'Report saved to report.json ' ) ;
61
63
62
64
$ metric = new Homogeneity ();
63
65
64
66
$ score = $ metric ->score ($ predictions , $ testing ->labels ());
65
67
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