Skip to content

Commit 8134e16

Browse files
committed
Update to ML 1.0
1 parent 039ac83 commit 8134e16

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ $ composer create-project rubix/credit
1111
```
1212

1313
## Requirements
14-
- [PHP](https://php.net) 7.2 or above
14+
- [PHP](https://php.net) 7.4 or above
1515

1616
#### Recommended
1717
- [Tensor extension](https://github.com/RubixML/Tensor) for faster training and inference
@@ -91,7 +91,11 @@ $estimator->train($dataset);
9191
The `steps()` method on Logistic Regression outputs the value of the [Cross Entropy](https://docs.rubixml.com/latest/neural-network/cost-functions/cross-entropy.html) cost function at each epoch from the last training session. You can plot those values by dumping them to a CSV file and then importing them into your favorite plotting software such as [Plotly](https://plot.ly/) or [Tableu](https://public.tableau.com/en-us/s/).
9292

9393
```php
94-
$losses = $estimator->steps();
94+
use Rubix\ML\Extractors\CSV;
95+
96+
$extractor = new CSV('progress.csv', true);
97+
98+
$extractor->export($estimator->steps());
9599
```
96100

97101
You'll notice that the loss should be decreasing at each epoch and changes in the loss value should get smaller the closer the learner is to converging on the minimum of the cost function.
@@ -270,7 +274,9 @@ Here is the output of the first two columns in the credit card dataset. We can s
270274
In addition, we'll save the stats to a JSON file so we can reference it later.
271275

272276
```php
273-
$stats->toJSON()->write('stats.json');
277+
use Rubix\ML\Persisters\Filesystem;
278+
279+
$stats->toJSON()->saveTo(new Filesystem('stats.json'));
274280
```
275281

276282
### Visualizing the Dataset
@@ -315,7 +321,9 @@ $dataset->apply($embedder);
315321
When the embedding is complete, we can save the dataset to a file so we can open it later in our favorite plotting software.
316322

317323
```php
318-
$dataset->toCSV()->write('embedding.csv');
324+
use Rubix\ML\Extractors\CSV;
325+
326+
$dataset->exportTo(new CSV('embedding.csv'));
319327
```
320328

321329
Now we're ready to execute the explore script and plot the embedding using our favorite plotting software.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
}
1919
],
2020
"require": {
21-
"php": ">=7.2",
22-
"rubix/ml": "^0.3.1"
21+
"php": ">=7.4",
22+
"rubix/ml": "^1.0"
2323
},
2424
"scripts": {
2525
"explore": "@php explore.php",

explore.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

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

5-
use Rubix\ML\Extractors\CSV;
5+
use Rubix\ML\Loggers\Screen;
66
use Rubix\ML\Datasets\Labeled;
7+
use Rubix\ML\Extractors\CSV;
78
use Rubix\ML\Transformers\NumericStringConverter;
9+
use Rubix\ML\Persisters\Filesystem;
810
use Rubix\ML\Transformers\OneHotEncoder;
911
use Rubix\ML\Transformers\ZScaleStandardizer;
10-
use Rubix\ML\Embedders\TSNE;
11-
use Rubix\ML\Other\Loggers\Screen;
12+
use Rubix\ML\Transformers\TSNE;
1213

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

@@ -23,11 +24,11 @@
2324

2425
echo $stats;
2526

26-
$stats->toJSON()->write('stats.json');
27+
$stats->toJSON()->saveTo(new Filesystem('stats.json'));
2728

2829
$logger->info('Stats saved to stats.json');
2930

30-
$dataset = $dataset->randomize()->head(2500);
31+
$dataset = $dataset->randomize()->head(1000);
3132

3233
$embedder = new TSNE(2, 20.0, 20);
3334

@@ -36,7 +37,6 @@
3637
$dataset->apply(new OneHotEncoder())
3738
->apply(new ZScaleStandardizer())
3839
->apply($embedder)
39-
->toCSV(['x', 'y', 'label'])
40-
->write('embedding.csv');
40+
->exportTo(new CSV('embedding.csv'));
4141

42-
$logger->info('Embedding saved to embedding.csv');
42+
$logger->info('Embedding saved to embedding.csv');

train.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

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

5+
use Rubix\ML\Loggers\Screen;
56
use Rubix\ML\Datasets\Labeled;
67
use Rubix\ML\Extractors\CSV;
78
use Rubix\ML\Transformers\NumericStringConverter;
89
use Rubix\ML\Transformers\OneHotEncoder;
910
use Rubix\ML\Transformers\ZScaleStandardizer;
1011
use Rubix\ML\Classifiers\LogisticRegression;
1112
use Rubix\ML\NeuralNet\Optimizers\StepDecay;
12-
use Rubix\ML\Other\Loggers\Screen;
1313
use Rubix\ML\CrossValidation\Reports\AggregateReport;
1414
use Rubix\ML\CrossValidation\Reports\ConfusionMatrix;
1515
use Rubix\ML\CrossValidation\Reports\MulticlassBreakdown;
16-
use Rubix\ML\Datasets\Unlabeled;
16+
use Rubix\ML\Persisters\Filesystem;
1717

1818
use function Rubix\ML\array_transpose;
1919

@@ -36,13 +36,9 @@
3636

3737
$estimator->train($training);
3838

39-
$importances = $estimator->featureImportances();
39+
$extractor = new CSV('progress.csv', true);
4040

41-
$losses = $estimator->steps();
42-
43-
Unlabeled::build(array_transpose([$losses]))
44-
->toCSV(['losses'])
45-
->write('progress.csv');
41+
$extractor->export($estimator->steps());
4642

4743
$logger->info('Progress saved to progress.csv');
4844

@@ -59,6 +55,6 @@
5955

6056
echo $results;
6157

62-
$results->toJSON()->write('report.json');
58+
$results->toJSON()->saveTo(new Filesystem('report.json'));
6359

6460
$logger->info('Report saved to report.json');

0 commit comments

Comments
 (0)