-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtrain.php
45 lines (32 loc) · 1.1 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
<?php
include __DIR__ . '/vendor/autoload.php';
use Rubix\ML\Loggers\Screen;
use Rubix\ML\Datasets\Labeled;
use Rubix\ML\Extractors\NDJSON;
use Rubix\ML\PersistentModel;
use Rubix\ML\Pipeline;
use Rubix\ML\Transformers\GaussianRandomProjector;
use Rubix\ML\Transformers\ZScaleStandardizer;
use Rubix\ML\Classifiers\SoftmaxClassifier;
use Rubix\ML\NeuralNet\Optimizers\Momentum;
use Rubix\ML\Persisters\Filesystem;
use Rubix\ML\Extractors\CSV;
ini_set('memory_limit', '-1');
$logger = new Screen();
$logger->info('Loading data into memory');
$dataset = Labeled::fromIterator(new NDJSON('train.ndjson'));
$estimator = new PersistentModel(
new Pipeline([
new GaussianRandomProjector(110),
new ZScaleStandardizer(),
], new SoftmaxClassifier(256, new Momentum(0.001))),
new Filesystem('har.rbx')
);
$estimator->setLogger($logger);
$estimator->train($dataset);
$extractor = new CSV('progress.csv', true);
$extractor->export($estimator->steps());
$logger->info('Progress saved to progress.csv');
if (strtolower(readline('Save this model? (y|[n]): ')) === 'y') {
$estimator->save();
}