You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ Here `learner` specifies the configuration the algorithm (the hyperparameters) w
24
24
`model` stores learned parameters and any byproducts of algorithm execution.
25
25
26
26
LearnAPI.jl is mostly method stubs and lots of documentation. It does not provide
27
-
meta-algorithms, such as cross-validation or hyperparameter optimization, but does aim to
27
+
meta-algorithms, such as cross-validation, hyperparameter optimization, or model composition, but does aim to
28
28
support such algorithms.
29
29
30
30
## Related packages
@@ -37,6 +37,8 @@ support such algorithms.
37
37
38
38
-[StatisticalMeasures.jl](https://github.com/JuliaAI/StatisticalMeasures.jl): Package providing metrics, compatible with LearnAPI.jl
39
39
40
+
-[StatsModels.jl](https://github.com/JuliaStats/StatsModels.jl): Provides the R-style formula implementation of data preprocessing handled by [LearnDataFrontEnds.jl](https://github.com/JuliaAI/LearnDataFrontEnds.jl)
41
+
40
42
### Selected packages providing alternative API's
41
43
42
44
The following alphabetical list of packages provide public base API's. Some provide
Copy file name to clipboardExpand all lines: docs/src/anatomy_of_an_implementation.md
+74-56Lines changed: 74 additions & 56 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
# Anatomy of an Implementation
2
2
3
-
The core LearnAPI.jl pattern looks like this:
3
+
LearnAPI.jl supports three core patterns. The default pattern, known as the
4
+
[`LearnAPI.Descriminative`](@ref) pattern, looks like this:
4
5
5
6
```julia
6
7
model =fit(learner, data)
@@ -10,38 +11,51 @@ predict(model, newdata)
10
11
Here `learner` specifies [hyperparameters](@ref hyperparameters), while `model` stores
11
12
learned parameters and any byproducts of algorithm execution.
12
13
13
-
Variations on this pattern:
14
+
[Transformers](@ref) ordinarily implement `transform` instead of `predict`. For more on
15
+
`predict` versus `transform`, see [Predict or transform?](@ref)
14
16
15
-
-[Transformers](@ref) ordinarily implement `transform` instead of `predict`. For more on
16
-
`predict` versus `transform`, see [Predict or transform?](@ref)
17
+
Two other `fit`/`predict`/`transform` patterns supported by LearnAPI.jl are:
18
+
[`LearnAPI.Generative`](@ref) which has the form:
17
19
18
-
-["Static" (non-generalizing) algorithms](@ref static_algorithms), which includes some
19
-
simple transformers and some clustering algorithms, have a `fit` that consumes no
20
-
`data`. Instead `predict` or `transform` does the heavy lifting.
20
+
```julia
21
+
model =fit(learner, data)
22
+
predict(model) # a single distribution, for example
23
+
```
21
24
22
-
- In [density estimation](@ref density_estimation), the `newdata` argument in `predict` is
23
-
missing.
25
+
and [`LearnAPI.Static`](@ref), which looks like this:
26
+
27
+
```julia
28
+
model =fit(learner) # no `data` argument
29
+
predict(model, data) # may mutate `model` to record byproducts of computation
30
+
```
24
31
25
-
These are the basic possibilities.
32
+
Do not read too much into the names for these patterns, which are formalized [here](@ref kinds_of_learner). Use may not always correspond to prior associations.
26
33
27
-
Elaborating on the core pattern above, this tutorial details an implementation of the
28
-
LearnAPI.jl for naive [ridge regression](https://en.wikipedia.org/wiki/Ridge_regression)
29
-
with no intercept. The kind of workflow we want to enable has been previewed in [Sample
30
-
workflow](@ref). Readers can also refer to the [demonstration](@ref workflow) of the
31
-
implementation given later.
34
+
Elaborating on the common `Descriminative`pattern above, this tutorial details an
35
+
implementation of the LearnAPI.jl for naive [ridge
36
+
regression](https://en.wikipedia.org/wiki/Ridge_regression)with no intercept. The kind of
37
+
workflow we want to enable has been previewed in [Sample workflow](@ref). Readers can also
38
+
refer to the [demonstration](@ref workflow) of the implementation given later.
32
39
33
-
## A basic implementation
40
+
!!! tip "Quick Start for new implementations"
34
41
35
-
See [here](@ref code) for code without explanations.
42
+
1. From this tutorial, read at least "[A basic implementation](@ref)" below.
43
+
1. Looking over the examples in "[Common Implementation Patterns](@ref patterns)", identify the appropriate core learner pattern above for your algorithm.
44
+
1. Implement `fit` (probably following an existing example). Read the [`fit`](@ref) document string to see what else may need to be implemented, paying particular attention to the "New implementations" section.
45
+
3. Rinse and repeat with each new method implemented.
46
+
4. Identify any additional [learner traits](@ref traits) that have appropriate overloadings; use the [`@trait`](@ref) macro to define these in one block.
47
+
5. Ensure your implementation includes the compulsory method [`LearnAPI.learner`](@ref) and compulsory traits [`LearnAPI.constructor`](@ref) and [`LearnAPI.functions`](@ref). Read and apply "[Testing your implementation](@ref)".
36
48
37
-
We suppose our algorithm's `fit` method consumes data in the form `(X, y)`, where
38
-
`X` is a suitable table¹ (the features) and `y` a vector (the target).
49
+
If you get stuck, refer back to this tutorial and the [Reference](@ref reference) sections.
39
50
40
-
!!! important
41
51
42
-
Implementations wishing to support other data
43
-
patterns may need to take additional steps explained under
44
-
[Other data patterns](@ref di) below.
52
+
## A basic implementation
53
+
54
+
See [here](@ref code) for code without explanations.
55
+
56
+
Let us suppose our algorithm's `fit` method is to consume data in the form `(X, y)`, where
57
+
`X` is a suitable table¹ (the features, a.k.a., covariates or predictors) and `y` a vector
58
+
(the target, a.k.a., labels or response).
45
59
46
60
The first line below imports the lightweight package LearnAPI.jl whose methods we will be
47
61
extending. The second imports libraries needed for the core algorithm.
@@ -110,7 +124,7 @@ Note that we also include `learner` in the struct, for it must be possible to re
110
124
The implementation of `fit` looks like this:
111
125
112
126
```@example anatomy
113
-
function LearnAPI.fit(learner::Ridge, data; verbosity=1)
127
+
function LearnAPI.fit(learner::Ridge, data; verbosity=LearnAPI.default_verbosity())
114
128
X, y = data
115
129
116
130
# data preprocessing:
@@ -158,6 +172,22 @@ If the kind of proxy is omitted, as in `predict(model, Xnew)`, then a fallback g
158
172
first element of the tuple returned by [`LearnAPI.kinds_of_proxy(learner)`](@ref), which
159
173
we overload appropriately below.
160
174
175
+
### Data deconstructors: `target` and `features`
176
+
177
+
LearnAPI.jl is flexible about the form of training `data`. However, to buy into
178
+
meta-functionality, such as cross-validation, we'll need to say something about the
179
+
structure of this data. We implement [`LearnAPI.target`](@ref) to say what
180
+
part of the data constitutes a [target variable](@ref proxy), and
181
+
[`LearnAPI.features`](@ref) to say what are the features (valid `newdata` in a
182
+
`predict(model, newdata)` call):
183
+
184
+
```@example anatomy
185
+
LearnAPI.target(learner::Ridge, (X, y)) = y
186
+
LearnAPI.features(learner::Ridge, (X, y)) = X
187
+
```
188
+
189
+
Another data deconstructor, for learners that support per-observation weights in training,
190
+
is [`LearnAPI.weights`](@ref).
161
191
162
192
### [Accessor functions](@id af)
163
193
@@ -241,15 +271,11 @@ the *type* of the argument.
241
271
### The `functions` trait
242
272
243
273
The last trait, `functions`, above returns a list of all LearnAPI.jl methods that can be
244
-
meaningfully applied to the learner or associated model, with the exception of traits. You
245
-
always include the first five you see here: `fit`, `learner`, `clone` ,`strip`,
246
-
`obs`. Here [`clone`](@ref) is a utility function provided by LearnAPI that you never
247
-
overload, while [`obs`](@ref) is discussed under [Providing a separate data front
248
-
end](@ref) below and is always included because it has a meaningful fallback. The
249
-
`features` method, here provided by a fallback, articulates how the features `X` can be
250
-
extracted from the training data `(X, y)`. We must also include `target` here to flag our
251
-
model as supervised; again the method itself is provided by a fallback valid in the
252
-
present case.
274
+
meaningfully applied to the learner or the output of `fit` (denoted `model` above), with
275
+
the exception of traits. You always include the first five you see here: `fit`, `learner`,
276
+
`clone` ,`strip`, `obs`. Here [`clone`](@ref) is a utility function provided by LearnAPI
277
+
that you never overload, while [`obs`](@ref) is discussed under [Providing a separate data
278
+
front end](@ref) below and is always included because it has a meaningful fallback.
253
279
254
280
See [`LearnAPI.functions`](@ref) for a checklist of what the `functions` trait needs to
255
281
return.
@@ -340,11 +366,6 @@ assumptions about data from those made above.
340
366
under [Providing a separate data front end](@ref) below; or (ii) overload the trait
341
367
[`LearnAPI.data_interface`](@ref) to specify a more relaxed data API.
342
368
343
-
- Where the form of data consumed by `fit` is different from that consumed by
344
-
`predict/transform` (as in classical supervised learning) it may be necessary to
345
-
explicitly overload the functions [`LearnAPI.features`](@ref) and (if supervised)
346
-
[`LearnAPI.target`](@ref). The same holds if overloading [`obs`](@ref); see below.
347
-
348
369
349
370
## Providing a separate data front end
350
371
@@ -414,7 +435,7 @@ The [`obs`](@ref) methods exist to:
414
435
415
436
!!! important
416
437
417
-
While many new learner implementations will want to adopt a canned data front end, such as those provided by [LearnDataFrontEnds.jl](https://juliaai.github.io/LearnAPI.jl/dev/), we
438
+
While many new learner implementations will want to adopt a canned data front end, such as those provided by [LearnDataFrontEnds.jl](https://juliaai.github.io/LearnDataFrontEnds.jl/dev/), we
418
439
focus here on a self-contained implementation of `obs` for the ridge example above, to show
0 commit comments