From de781dd9b0f22a8d65cb41247ffbb5498154ec42 Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Thu, 6 Aug 2020 18:15:29 -0500 Subject: [PATCH] Update to Rubix ML 0.1.0 --- README.md | 20 +++++++++++++++++--- composer.json | 3 +-- train.php | 11 +++++------ validate.php | 4 +++- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 20b055c..9c6eb67 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) @@ -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. @@ -187,7 +202,6 @@ The output of the report should look something like the output below. Nice work! "cardinality": 2947 }, } - ] ``` diff --git a/composer.json b/composer.json index 9d4ef1c..33a3142 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/train.php b/train.php index 5400e02..c0c529d 100644 --- a/train.php +++ b/train.php @@ -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; @@ -30,7 +30,7 @@ new Filesystem('har.model') ); -$estimator->setLogger(new Screen('HAR')); +$estimator->setLogger(new Screen()); echo 'Training ...' . PHP_EOL; @@ -38,10 +38,9 @@ $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; diff --git a/validate.php b/validate.php index a4a640a..b231594 100644 --- a/validate.php +++ b/validate.php @@ -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; \ No newline at end of file