Skip to content

Commit

Permalink
Update to Rubix ML 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdalpino committed Aug 6, 2020
1 parent a18aa6f commit de781dd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Since Softmax Classifier implements the [Verbose](https://docs.rubixml.com/en/la
```php
use Rubix\ML\Other\Loggers\Screen;

$estimator->setLogger(new Screen('HAR'));
$estimator->setLogger(new Screen());
```

### Training
Expand All @@ -91,6 +91,17 @@ During training, the learner will record the training loss at each epoch which w
$losses = $estimator->steps();
```

Then we'll save the losses to a CSV file using the `toCSV` method on the [Unlabeled]() dataset object.

```php
use Rubix\ML\Datasets\Unlabeled;
use function Rubix\ML\array_transpose;

Unlabeled::build(array_transpose([$losses]))
->toCSV(['losses'])
->write('progress.csv');
```

This is an example of a line plot of the Cross Entropy cost function from a training session. As you can see, the model learns quickly during the early epochs with slower training nearing the final stage as the learner fine-tunes the model parameters.

![Cross Entropy Loss](https://raw.githubusercontent.com/RubixML/HAR/master/docs/images/training-loss.svg?sanitize=true)
Expand Down Expand Up @@ -150,10 +161,14 @@ $report = new AggregateReport([
]);
```

Now, generate the report using the predictions and labels from the testing set.
Now, generate the report using the predictions and labels from the testing set. In addition, we'll echo the report to the console and save the results to a JSON file for reference later.

```php
$results = $report->generate($predictions, $dataset->labels());

echo $results;

$results->toJSON()->write('report.json');
```

To execute the validation script, enter the following command at the command prompt.
Expand Down Expand Up @@ -187,7 +202,6 @@ The output of the report should look something like the output below. Nice work!
"cardinality": 2947
},
}

]
```

Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
],
"require": {
"php": ">=7.2",
"league/csv": "^9.5",
"rubix/ml": "^0.1.0-rc2"
"rubix/ml": "^0.1.0"
},
"suggest": {
"ext-tensor": "For faster training and inference"
Expand Down
11 changes: 5 additions & 6 deletions train.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Rubix\ML\NeuralNet\Optimizers\Momentum;
use Rubix\ML\Persisters\Filesystem;
use Rubix\ML\Other\Loggers\Screen;
use League\Csv\Writer;
use Rubix\ML\Datasets\Unlabeled;

use function Rubix\ML\array_transpose;

Expand All @@ -30,18 +30,17 @@
new Filesystem('har.model')
);

$estimator->setLogger(new Screen('HAR'));
$estimator->setLogger(new Screen());

echo 'Training ...' . PHP_EOL;

$estimator->train($dataset);

$losses = $estimator->steps();

$writer = Writer::createFromPath('progress.csv', 'w+');

$writer->insertOne(['loss']);
$writer->insertAll(array_transpose([$losses]));
Unlabeled::build(array_transpose([$losses]))
->toCSV(['losses'])
->write('progress.csv');

echo 'Progress saved to progress.csv' . PHP_EOL;

Expand Down
4 changes: 3 additions & 1 deletion validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

$results = $report->generate($predictions, $dataset->labels());

file_put_contents('report.json', json_encode($results, JSON_PRETTY_PRINT));
echo $results;

$results->toJSON()->write('report.json');

echo 'Report saved to report.json' . PHP_EOL;

0 comments on commit de781dd

Please sign in to comment.