-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain.php
52 lines (44 loc) · 1.29 KB
/
train.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
46
47
48
49
50
51
52
<?php
if (!($loader = @include __DIR__ . '/vendor/autoload.php')) {
die(<<<EOT
You need to install the project dependencies using Composer:
$ wget http://getcomposer.org/composer.phar
OR
$ curl -s https://getcomposer.org/installer | php
$ php composer.phar install --dev
$ phpunit
EOT
);
}
use Rubix\ML\Clusterers\KMeans;
use Rubix\ML\Extractors\ColumnPicker;
use Rubix\ML\Datasets\Unlabeled;
use Rubix\ML\Extractors\CSV;
use Rubix\ML\PersistentModel;
use Rubix\ML\Persisters\Filesystem;
use Rubix\ML\Transformers\NumericStringConverter;
use Rubix\ML\Transformers\ZScaleStandardizer;
// Import the Data
$dataset = Unlabeled::fromIterator(
(new ColumnPicker(
new CSV('./data/customers.csv', true), [
'recency',
'frequency',
'monetary',
])
)
)->apply(new NumericStringConverter())
;
//dump($dataset->describe());
//dump($dataset->head());
// Scale and center the Data
// Same behavior than Scikit-Learn StandardScaler()
$dataset->apply(new ZScaleStandardizer());
// Set up the Machine Learning model : MiniBatch KMeans
// The first argument is the number of clusters we want to create
$kmeans = new PersistentModel(
new KMeans(3),
new Filesystem('./models/customers_clustering.rbx', true)
);
$kmeans->train($dataset);
$kmeans->save();