diff --git a/predict.php b/predict.php index 29d0e33..c2951ee 100644 --- a/predict.php +++ b/predict.php @@ -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; @@ -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()); @@ -23,7 +26,7 @@ $estimator = PersistentModel::load(new Filesystem('housing.model')); -echo 'Making predictions ...' . PHP_EOL; +$logger->info('Making predictions'); $predictions = $estimator->predict($dataset); @@ -31,4 +34,4 @@ ->toCSV(['Id', 'SalePrice']) ->write('predictions.csv'); -echo 'Predictions saved to predictions.csv' . PHP_EOL; \ No newline at end of file +$logger->info('Predictions saved to predictions.csv'); \ No newline at end of file diff --git a/train.php b/train.php index db0589a..0a65367 100644 --- a/train.php +++ b/train.php @@ -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; @@ -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', @@ -41,6 +43,8 @@ $dataset = Labeled::fromIterator($extractor); +$logger->info('Preprocessing'); + $dataset->apply(new NumericStringConverter()) ->apply(new MissingDataImputer()) ->transformLabels('intval'); @@ -50,9 +54,7 @@ new Filesystem('housing.model', true) ); -$estimator->setLogger(new Screen()); - -echo 'Training ...' . PHP_EOL; +$estimator->setLogger($logger); $estimator->train($dataset); @@ -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();