Skip to content

Commit 249e1e8

Browse files
authored
Merge pull request #36 from JuliaAI/tweaks
doc and test tweaks
2 parents cf56728 + 8a00b3b commit 249e1e8

File tree

5 files changed

+32
-34
lines changed

5 files changed

+32
-34
lines changed

.github/codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ coverage:
66
removed_code_behavior: fully_covered_patch
77
patch:
88
default:
9-
target: 80%coverage:
9+
target: 80

docs/src/fit_update.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ predict(model, Distribution(), X)
4545

4646
See also [Classification](@ref) and [Regression](@ref).
4747

48-
### Tranformers
48+
### Transformers
4949

5050
A dimension-reducing transformer, `algorithm` might be used in this way:
5151

src/fit_update.jl

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ returning an object, `model`, on which other methods, such as [`predict`](@ref)
99
[`transform`](@ref), can be dispatched. [`LearnAPI.functions(algorithm)`](@ref) returns a
1010
list of methods that can be applied to either `algorithm` or `model`.
1111
12-
The second signature is provided by algorithms that do not generalize to new observations
13-
(called *static algorithms*). In that case, `transform(model, data)` or `predict(model,
14-
..., data)` carries out the actual algorithm execution, writing any byproducts of that
15-
operation to the mutable object `model` returned by `fit`.
16-
1712
For example, a supervised classifier might have a workflow like this:
1813
1914
```julia
2015
model = fit(algorithm, (X, y))
2116
ŷ = predict(model, Xnew)
2217
```
2318
19+
The second signature, with `data` omitted, is provided by algorithms that do not
20+
generalize to new observations (called *static algorithms*). In that case,
21+
`transform(model, data)` or `predict(model, ..., data)` carries out the actual algorithm
22+
execution, writing any byproducts of that operation to the mutable object `model` returned
23+
by `fit`.
24+
2425
Use `verbosity=0` for warnings only, and `-1` for silent training.
2526
2627
See also [`predict`](@ref), [`transform`](@ref), [`inverse_transform`](@ref),
@@ -41,7 +42,7 @@ If `data` encapsulates a *target* variable, as defined in LearnAPI.jl documentat
4142
[`transform`](@ref) are implemented and consume data, then
4243
[`LearnAPI.features(data)`](@ref) must return something that can be passed as data to
4344
these methods. A fallback returns `first(data)` if `data` is a tuple, and `data`
44-
otherwise`.
45+
otherwise.
4546
4647
The LearnAPI.jl specification has nothing to say regarding `fit` signatures with more than
4748
two arguments. For convenience, for example, an algorithm is free to implement a slurping
@@ -63,16 +64,6 @@ Return an updated version of the `model` object returned by a previous [`fit`](@
6364
`update` call, but with the specified hyperparameter replacements, in the form `p1=value1,
6465
p2=value2, ...`.
6566
66-
Provided that `data` is identical with the data presented in a preceding `fit` call *and*
67-
there is at most one hyperparameter replacement, as in the example below, execution is
68-
semantically equivalent to the call `fit(algorithm, data)`, where `algorithm` is
69-
`LearnAPI.algorithm(model)` with the specified replacements. In some cases (typically,
70-
when changing an iteration parameter) there may be a performance benefit to using `update`
71-
instead of retraining ab initio.
72-
73-
If `data` differs from that in the preceding `fit` or `update` call, or there is more than
74-
one hyperparameter replacement, then behaviour is algorithm-specific.
75-
7667
```julia
7768
algorithm = MyForest(ntrees=100)
7869
@@ -83,6 +74,16 @@ model = fit(algorithm, data)
8374
model = update(model, data; ntrees=150)
8475
```
8576
77+
Provided that `data` is identical with the data presented in a preceding `fit` call *and*
78+
there is at most one hyperparameter replacement, as in the above example, execution is
79+
semantically equivalent to the call `fit(algorithm, data)`, where `algorithm` is
80+
`LearnAPI.algorithm(model)` with the specified replacements. In some cases (typically,
81+
when changing an iteration parameter) there may be a performance benefit to using `update`
82+
instead of retraining ab initio.
83+
84+
If `data` differs from that in the preceding `fit` or `update` call, or there is more than
85+
one hyperparameter replacement, then behaviour is algorithm-specific.
86+
8687
See also [`fit`](@ref), [`update_observations`](@ref), [`update_features`](@ref).
8788
8889
# New implementations
@@ -102,11 +103,6 @@ Return an updated version of the `model` object returned by a previous [`fit`](@
102103
`update` call given the new observations present in `new_data`. One may additionally
103104
specify hyperparameter replacements in the form `p1=value1, p2=value2, ...`.
104105
105-
When following the call `fit(algorithm, data)`, the `update` call is semantically
106-
equivalent to retraining ab initio using a concatenation of `data` and `new_data`,
107-
*provided there are no hyperparameter replacements.* Behaviour is otherwise
108-
algorithm-specific.
109-
110106
```julia-repl
111107
algorithm = MyNeuralNetwork(epochs=10, learning_rate=0.01)
112108
@@ -117,6 +113,11 @@ model = fit(algorithm, data)
117113
model = update_observations(model, new_data; epochs=2, learning_rate=0.1)
118114
```
119115
116+
When following the call `fit(algorithm, data)`, the `update` call is semantically
117+
equivalent to retraining ab initio using a concatenation of `data` and `new_data`,
118+
*provided there are no hyperparameter replacements* (which rules out the example
119+
above). Behaviour is otherwise algorithm-specific.
120+
120121
See also [`fit`](@ref), [`update`](@ref), [`update_features`](@ref).
121122
122123
# Extended help

src/predict_transform.jl

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ and probability density/mass functions if `kind_of_proxy = Distribution()`. List
6464
options with [`LearnAPI.kinds_of_proxy(algorithm)`](@ref), where `algorithm =
6565
LearnAPI.algorithm(model)`.
6666
67+
```julia
68+
model = fit(algorithm, (X, y))
69+
predict(model, Point(), Xnew)
70+
```
71+
6772
The shortcut `predict(model, data)` calls the first method with an algorithm-specific
6873
`kind_of_proxy`, namely the first element of [`LearnAPI.kinds_of_proxy(algorithm)`](@ref),
6974
which lists all supported target proxies.
@@ -73,16 +78,6 @@ The argument `model` is anything returned by a call of the form `fit(algorithm,
7378
If `LearnAPI.features(LearnAPI.algorithm(model)) == nothing`, then argument `data` is
7479
omitted in both signatures. An example is density estimators.
7580
76-
# Example
77-
78-
In the following, `algorithm` is some supervised learning algorithm with
79-
training features `X`, training target `y`, and test features `Xnew`:
80-
81-
```julia
82-
model = fit(algorithm, (X, y)) # or `fit(algorithm, X, y)`
83-
predict(model, Point(), Xnew)
84-
```
85-
8681
See also [`fit`](@ref), [`transform`](@ref), [`inverse_transform`](@ref).
8782
8883
# Extended help

test/accessor_functions.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using Test
22
using LearnAPI
33

4-
@test strip("junk") == "junk"
4+
@test LearnAPI.strip("junk") == "junk"
5+
6+
true

0 commit comments

Comments
 (0)