Skip to content

Commit be4097e

Browse files
committed
Improve the docs
1 parent d5128e5 commit be4097e

14 files changed

+90
-68
lines changed

docs/basic-introduction.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ We can verify that the learner has been trained by calling the `trained()` metho
6767
var_dump($estimator->trained());
6868
```
6969

70-
```sh
70+
```
7171
bool(true)
7272
```
7373

@@ -96,16 +96,17 @@ $dataset = new Unlabeled($samples);
9696

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

99-
var_dump($predictions);
99+
print_r($predictions);
100100
```
101101

102-
```sh
103-
array(4) {
104-
[0] => 'married'
105-
[1] => 'divorced'
106-
[2] => 'divorced'
107-
[4] => 'married'
108-
}
102+
```php
103+
Array
104+
(
105+
[0] => married
106+
[1] => divorced
107+
[2] => divorced
108+
[3] => married
109+
)
109110
```
110111

111112
The output of the estimator are the predicted class labels of the unknown samples. We could either trust these predictions as-is or we could proceed to further evaluate the model. In the next section, we'll learn how to test its accuracy using a process called cross validation.
@@ -152,4 +153,4 @@ The return value is the accuracy score which can be interpreted as the degree to
152153
More info can be found in the [Cross Validation](cross-validation.md) section of the docs.
153154

154155
## Next Steps
155-
Congratulations! You've completed the basic introduction to machine learning in PHP with Rubix ML. For a more in-depth tutorial using the K Nearest Neighbors classifier and a real dataset, check out the [Divorce Predictor](https://github.com/RubixML/Divorce) tutorial and example project. Have fun!
156+
Congratulations! You've completed the basic introduction to machine learning in PHP with Rubix ML. For a more in-depth tutorial using the K Nearest Neighbors classifier and a real dataset, check out the [Divorce Predictor](https://github.com/RubixML/Divorce) tutorial and example project. Have fun!

docs/cross-validation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ $score = $metric->score($predictions, $testing->labels());
3939
echo $score;
4040
```
4141

42-
```sh
42+
```
4343
0.85
4444
```
4545

@@ -167,7 +167,7 @@ $score = $validator->test($estimator, $dataset, new FBeta());
167167
echo $score;
168168
```
169169

170-
```sh
170+
```
171171
0.9175
172172
```
173173

docs/extracting-data.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ We can check the number of records that were imported by calling the `numSamples
2929
echo $dataset->numSamples();
3030
```
3131

32-
```sh
32+
```
3333
5000
3434
```
3535

docs/hyper-parameter-tuning.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ $score = $metric->score($predictions, $testing->labels());
2323
echo $score;
2424
```
2525

26+
```
27+
-4.75
28+
```
29+
2630
## Hyper-parameter Optimization
2731
In distinction to manual tuning, Hyper-parameter optimization is an AutoML technique that employs search and meta-learning strategies to explore various algorithm configurations. In Rubix ML, hyper-parameter optimizers are implemented as meta-estimators that wrap a base learner whose hyper-parameters we wish to optimize.
2832

@@ -58,7 +62,7 @@ We can also dump the selected hyper-parameters by calling the `params()` method
5862
print_r($estimator->base()->params());
5963
```
6064

61-
```sh
65+
```php
6266
Array
6367
(
6468
[k] => 3
@@ -85,4 +89,4 @@ use Rubix\ML\Helpers\Params;
8589
$params = [
8690
Params::ints(1, 10, 4), [true, false], // ...
8791
];
88-
```
92+
```

docs/inference.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $predictions = $estimator->predict($dataset);
2323
print_r($predictions);
2424
```
2525

26-
```sh
26+
```php
2727
Array
2828
(
2929
[0] => cat
@@ -41,7 +41,7 @@ $probabilities = $estimator->proba($dataset);
4141
print_r($probabilities);
4242
```
4343

44-
```sh
44+
```php
4545
Array
4646
(
4747
[0] => Array
@@ -52,9 +52,9 @@ Array
5252
)
5353
[1] => Array
5454
(
55-
[cat] => 3.0
56-
[dog] => 6.0
57-
[frog] => 1.0
55+
[cat] => 0.3
56+
[dog] => 0.6
57+
[frog] => 0.1
5858
)
5959
[2] => Array
6060
(
@@ -74,7 +74,7 @@ $scores = $estimator->score($dataset);
7474
print_r($scores);
7575
```
7676

77-
```sh
77+
```php
7878
Array
7979
(
8080
[0] => 0.35033

docs/learner.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ public trained() : bool
2424
var_dump($estimator->trained());
2525
```
2626

27-
```sh
27+
```
2828
bool(true)
2929
```

docs/model-persistence.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Model persistence is the ability to save and subsequently load a learner's state in another process. Trained estimators can be used for real-time inference by loading the model onto a server or they can be saved to make predictions in batches offline at a later time. Estimators that implement the [Persistable](persistable.md) interface are able to have their internal state captured between processes. In addition, the library provides the [Persistent Model](persistent-model.md) meta-estimator that acts as a wrapper for persistable estimators.
33

44
## Serialization
5-
Serialization occurs in between saving and loading a model and can be thought of as packaging the model's parameters. The data can be in a lightweight format such as with PHP's [Native](serializers/native.md) serializer or in a more robust format such as with the library's own [RBX](serializers/rbx.md) serializer. In the this example, we'll demonstrate how to encode a Persistable learner using the compressed RBX format, save the encoding with a [Persister](persisters/api.md), and then how to deserialize the encoding.
5+
Serialization occurs in between saving and loading a model and can be thought of as packaging the model's parameters. The data can be in a lightweight format such as with PHP's [Native](serializers/native.md) serializer or in a robust format such as [RBX](serializers/rbx.md). In the this example, we'll demonstrate how to encode a Persistable learner using the compressed RBX format, save the encoding with a [Persister](persisters/api.md), and then how to deserialize the encoding.
66

77
```php
88
use Rubix\ML\Classifiers\RandomForest;
@@ -15,13 +15,11 @@ $serializer = new RBX();
1515

1616
$encoding = $serializer->serialize($estimator);
1717

18-
19-
2018
$estimator = $serializer->deserialize($encoding);
2119
```
2220

2321
!!! note
24-
Due to a limitation in PHP, anonymous classes and functions (*closures*) are not able to be deserialized. Avoid adding anonymous classes or functions to an object that you intend to persist.
22+
Due to a limitation in PHP, anonymous classes and functions (*closures*) are not able to be deserialized. Therefore, avoid anonymous classes or functions if you intend to persist the model.
2523

2624
## Persistent Model Meta-estimator
2725
The persistence subsystem can be interfaces at a low level with Serializer and Persister objects or it can be interacted with at a higher level using the [Persistent Model](persistent-model.md) meta-estimator. It is a decorator that provides `save()` and `load()` methods giving the estimator the ability to save and load itself.
@@ -38,7 +36,7 @@ $estimator->save();
3836
```
3937

4038
## Persisting Transformers
41-
In addition to Learners, the persistence subsystem can be used to individually save and load any Stateful transformer that implements the [Persistable](persistable.md) interface . In the example below we'll fit a transformer to a dataset and then save it to the [Filesystem](persisters/filesystem.md).
39+
In addition to Learners, the persistence subsystem can be used to individually save and load any Stateful transformer that implements the [Persistable](persistable.md) interface. In the example below we'll fit a transformer to a dataset and then save it to the [Filesystem](persisters/filesystem.md).
4240

4341
```php
4442
use Rubix\ML\Transformers\OneHotEncoder;
@@ -47,10 +45,10 @@ use Rubix\ML\Persisters\Filesystem;
4745

4846
$transformer = new OneHotEncoder();
4947

50-
// Fit transformer
51-
5248
$serializer = new RBX();
5349

50+
$transformer->fit($dataset);
51+
5452
$serializer->serialize($transformer)->saveTo(new Filesystem('example.rbx'));
5553
```
5654

docs/online.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public partial(Dataset $dataset) : void
1010
```php
1111
$folds = $dataset->fold(3);
1212

13-
$estimator->partial($folds[0]);
13+
$estimator->train($folds[0]);
1414

1515
$estimator->partial($folds[1]);
1616

docs/persistable.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
11
# Persistable
2-
An estimator that implements the Persistable interface can be saved and loaded by a [Persister](persisters/api.md) object or using the [Persistent Model](persistent-model.md) meta-estimator. The interface provides no additional methods otherwise.
2+
An estimator that implements the Persistable interface can be serialized by a [Serializer](serializers/api.md) or save and loaded using the [Persistent Model](persistent-model.md) meta-estimator.
3+
4+
To return the current class revision hash:
5+
```php
6+
public revision() : string
7+
```
8+
9+
```php
10+
echo $persistable->revision();
11+
```
12+
13+
```
14+
e7eeec9a
15+
```

docs/probabilistic.md

+20-16
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,26 @@ public proba(Dataset $dataset) : array
1010
```php
1111
$probabilities = $estimator->proba($dataset);
1212

13-
var_dump($probabilities);
13+
print_r($probabilities);
1414
```
1515

16-
```sh
17-
array(2) {
18-
[0] => array(2) {
19-
['monster'] => 0.975,
20-
['not monster'] => 0.025,
21-
}
22-
[1] => array(2) {
23-
['monster'] => 0.2,
24-
['not monster'] => 0.8,
25-
}
26-
[2] => array(2) {
27-
['monster'] => 0.6,
28-
['not monster'] => 0.4,
29-
}
30-
}
16+
```php
17+
Array
18+
(
19+
[0] => Array
20+
(
21+
[monster] => 0.6
22+
[not monster] => 0.4
23+
)
24+
[1] => Array
25+
(
26+
[monster] => 0.5
27+
[not monster] => 0.5
28+
)
29+
[2] => Array
30+
(
31+
[monster] => 0.2
32+
[not monster] => 0.8
33+
)
34+
)
3135
```

docs/ranks-features.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ $estimator->train($dataset);
1212

1313
$importances = $estimator->featureImportances();
1414

15-
var_dump($importances);
15+
print_r($importances);
1616
```
1717

18-
```sh
19-
array(4) {
20-
[0]=> float(0.047576266783176)
21-
[1]=> float(0.3794817175945)
22-
[2]=> float(0.53170249909942)
23-
[3]=> float(0.041239516522901)
24-
}
18+
```php
19+
Array
20+
(
21+
[0] => 0.04757
22+
[1] => 0.37948
23+
[2] => 0.53170
24+
[3] => 0.04123
25+
)
2526
```

docs/scoring.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ public score(Dataset $dataset) : array
1010
```php
1111
$scores = $estimator->score($dataset);
1212

13-
var_dump($scores);
13+
print_r($scores);
1414
```
1515

16-
```sh
17-
array(3) {
18-
[0]=> float(0.35033859096744)
19-
[1]=> float(0.40992076925443)
20-
[2]=> float(1.68163357834096)
21-
}
16+
```php
17+
Array
18+
(
19+
[0] => 0.35033
20+
[1] => 0.40992
21+
[2] => 1.68153
22+
)
2223
```

docs/training.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ $estimator->setLogger(new Screen());
4646
$estimator->train($dataset);
4747
```
4848

49-
```sh
49+
```
5050
[2020-09-04 08:39:04] INFO: Logistic Regression (batch_size: 128, optimizer: Adam (rate: 0.01, momentum_decay: 0.1, norm_decay: 0.001), alpha: 0.0001, epochs: 1000, min_change: 0.0001, window: 5, cost_fn: Cross Entropy) initialized
5151
[2020-09-04 08:39:04] INFO: Epoch 1 - Cross Entropy: 0.16895133388673
5252
[2020-09-04 08:39:04] INFO: Epoch 2 - Cross Entropy: 0.16559247705179
@@ -101,9 +101,9 @@ print_r($importances);
101101
```sh
102102
Array
103103
(
104-
[0] => 0.047576266783176
105-
[1] => 0.3794817175945
106-
[2] => 0.53170249909942
107-
[3] => 0.041239516522901
104+
[0] => 0.04757
105+
[1] => 0.37948
106+
[2] => 0.53170
107+
[3] => 0.04123
108108
)
109109
```

docs/verbose.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ $estimator->setLogger(new Screen('example'));
2424
$estimator->train($dataset);
2525
```
2626

27-
```sh
27+
```
2828
[2020-08-05 04:26:11] INFO: Learner init Adaline {batch_size: 128, optimizer: Adam {rate: 0.01, momentum_decay: 0.1, norm_decay: 0.001}, alpha: 0.0001, epochs: 100, min_change: 0.001, window: 5, cost_fn: Huber Loss {alpha: 1}}
2929
[2020-08-05 04:26:11] INFO: Training started
3030
[2020-08-05 04:26:11] example.INFO: Epoch 1 - Huber Loss {alpha: 1}: 0.36839299586132

0 commit comments

Comments
 (0)