forked from RubixML/Credit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexplore.php
40 lines (25 loc) · 1017 Bytes
/
explore.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
<?php
include __DIR__ . '/vendor/autoload.php';
use Rubix\ML\Extractors\CSV;
use Rubix\ML\Datasets\Labeled;
use Rubix\ML\Transformers\NumericStringConverter;
use Rubix\ML\Transformers\OneHotEncoder;
use Rubix\ML\Transformers\ZScaleStandardizer;
use Rubix\ML\Embedders\TSNE;
use Rubix\ML\Other\Loggers\Screen;
ini_set('memory_limit', '-1');
echo 'Loading data into memory ...' . PHP_EOL;
$dataset = Labeled::fromIterator(new CSV('dataset.csv', true))
->apply(new NumericStringConverter());
$stats = $dataset->describe();
file_put_contents('stats.json', json_encode($stats, JSON_PRETTY_PRINT));
echo 'Stats saved to stats.json' . PHP_EOL;
$dataset = $dataset->randomize()->head(2000);
$embedder = new TSNE(2, 20.0, 20);
$embedder->setLogger(new Screen('credit'));
echo 'Embedding ...' . PHP_EOL;
$dataset->apply(new OneHotEncoder())
->apply(new ZScaleStandardizer())
->apply($embedder);
file_put_contents('embedding.csv', $dataset->toCsv());
echo 'Embedding saved to embedding.csv' . PHP_EOL;