Skip to content

Commit

Permalink
Use logger instead of echo
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdalpino committed Aug 7, 2020
1 parent ace10ab commit 9bddbba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
9 changes: 6 additions & 3 deletions predict.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

include __DIR__ . '/vendor/autoload.php';

use Rubix\ML\Other\Loggers\Screen;
use Rubix\ML\Datasets\Unlabeled;
use Rubix\ML\Extractors\CSV;
use Rubix\ML\Transformers\NumericStringConverter;
Expand All @@ -12,7 +13,9 @@

ini_set('memory_limit', '-1');

echo 'Loading data into memory ...' . PHP_EOL;
$logger = new Screen();

$logger->info('Loading data into memory');

$dataset = Unlabeled::fromIterator(new CSV('unknown.csv', true))
->apply(new NumericStringConverter());
Expand All @@ -23,12 +26,12 @@

$estimator = PersistentModel::load(new Filesystem('housing.model'));

echo 'Making predictions ...' . PHP_EOL;
$logger->info('Making predictions');

$predictions = $estimator->predict($dataset);

Unlabeled::build(array_transpose([$ids, $predictions]))
->toCSV(['Id', 'SalePrice'])
->write('predictions.csv');

echo 'Predictions saved to predictions.csv' . PHP_EOL;
$logger->info('Predictions saved to predictions.csv');
14 changes: 8 additions & 6 deletions train.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

include __DIR__ . '/vendor/autoload.php';

use Rubix\ML\Other\Loggers\Screen;
use Rubix\ML\Datasets\Labeled;
use Rubix\ML\Extractors\CSV;
use Rubix\ML\Extractors\ColumnPicker;
Expand All @@ -11,14 +12,15 @@
use Rubix\ML\Regressors\GradientBoost;
use Rubix\ML\Regressors\RegressionTree;
use Rubix\ML\Persisters\Filesystem;
use Rubix\ML\Other\Loggers\Screen;
use Rubix\ML\Datasets\Unlabeled;

use function Rubix\ML\array_transpose;

ini_set('memory_limit', '-1');

echo 'Loading data into memory ...' . PHP_EOL;
$logger = new Screen();

$logger->info('Loading data into memory');

$extractor = new ColumnPicker(new CSV('dataset.csv', true), [
'MSSubClass', 'MSZoning', 'LotFrontage', 'LotArea', 'Street', 'Alley',
Expand All @@ -41,6 +43,8 @@

$dataset = Labeled::fromIterator($extractor);

$logger->info('Preprocessing');

$dataset->apply(new NumericStringConverter())
->apply(new MissingDataImputer())
->transformLabels('intval');
Expand All @@ -50,9 +54,7 @@
new Filesystem('housing.model', true)
);

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

echo 'Training ...' . PHP_EOL;
$estimator->setLogger($logger);

$estimator->train($dataset);

Expand All @@ -63,7 +65,7 @@
->toCSV(['scores', 'losses'])
->write('progress.csv');

echo 'Progress saved to progress.csv' . PHP_EOL;
$logger->info('Progress saved to progress.csv');

if (strtolower(readline('Save this model? (y|[n]): ')) === 'y') {
$estimator->save();
Expand Down

0 comments on commit 9bddbba

Please sign in to comment.