From 765b1b7387c98278b5ffa936a6d8226b3c50b2b1 Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Sat, 8 May 2021 13:25:30 -0500 Subject: [PATCH] Update to ML 1.0 --- README.md | 10 +--------- composer.json | 4 ++-- train.php | 15 +++++++-------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index e66f049..68eb1e7 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ $ composer create-project rubix/iris ``` ## Requirements -- [PHP](https://php.net) 7.2 or above +- [PHP](https://php.net) 7.4 or above ## Tutorial @@ -74,8 +74,6 @@ use Rubix\ML\CrossValidation\Metrics\Accuracy; $metric = new Accuracy(); $score = $metric->score($predictions, $testing->labels()); - -echo 'Accuracy is ' . (string) ($score * 100.0) . '%' . PHP_EOL; ``` Now you're ready to run the training script from the command line. @@ -83,12 +81,6 @@ Now you're ready to run the training script from the command line. php train.php ``` -**Output** - -```sh -Accuracy is 90% -``` - ### Next Steps Congratulations on completing the introduction to machine learning in PHP with Rubix ML using the Iris dataset. Now you're ready to experiment on your own. For example, you may want to try different values of `k` or swap out the default [Euclidean](https://docs.rubixml.com/latest/kernels/distance/euclidean.html) distance kernel for another one such as [Manhattan](https://docs.rubixml.com/latest/kernels/distance/manhattan.html) or [Minkowski](https://docs.rubixml.com/latest/kernels/distance/minkowski.html). diff --git a/composer.json b/composer.json index fcf74a2..8143976 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,8 @@ } ], "require": { - "php": ">=7.2", - "rubix/ml": "^0.3.0" + "php": ">=7.4", + "rubix/ml": "^1.0" }, "scripts": { "train": "@php train.php" diff --git a/train.php b/train.php index 0298da8..4728632 100644 --- a/train.php +++ b/train.php @@ -2,12 +2,15 @@ include __DIR__ . '/vendor/autoload.php'; +use Rubix\ML\Loggers\Screen; use Rubix\ML\Datasets\Labeled; use Rubix\ML\Extractors\NDJSON; use Rubix\ML\Classifiers\KNearestNeighbors; use Rubix\ML\CrossValidation\Metrics\Accuracy; -echo 'Loading data into memory ...' . PHP_EOL; +$logger = new Screen(); + +$logger->info('Loading data into memory'); $training = Labeled::fromIterator(new NDJSON('dataset.ndjson')); @@ -15,20 +18,16 @@ $estimator = new KNearestNeighbors(5); -echo 'Training ...' . PHP_EOL; +$logger->info('Training'); $estimator->train($training); -echo 'Making predictions ...' . PHP_EOL; +$logger->info('Making predictions'); $predictions = $estimator->predict($testing); -echo 'Example predictions:' . PHP_EOL; - -print_r(array_slice($predictions, 0, 3)); - $metric = new Accuracy(); $score = $metric->score($predictions, $testing->labels()); -echo 'Accuracy is ' . (string) ($score * 100.0) . '%' . PHP_EOL; +$logger->info("Accuracy is $score");