@@ -5,26 +5,34 @@ regression](https://en.wikipedia.org/wiki/Ridge_regression) with no intercept. T
5
5
workflow we want to enable has been previewed in [ Sample workflow] ( @ref ) . Readers can also
6
6
refer to the [ demonstration] (@ref workflow) of the implementation given later.
7
7
8
- For a transformer, implementations ordinarily implement ` transform ` instead of
8
+ A transformer ordinarily implements ` transform ` instead of
9
9
` predict ` . For more on ` predict ` versus ` transform ` , see [ Predict or transform?] ( @ref )
10
10
11
11
!!! note
12
12
13
13
New implementations of `fit`, `predict`, etc,
14
14
always have a *single* `data` argument, as in
15
15
`LearnAPI.fit(algorithm, data; verbosity=1) = ...`.
16
- For convenience, user calls like `fit(algorithm, X, y)` automatically fallback
16
+ For convenience, user- calls, such as `fit(algorithm, X, y)`, automatically fallback
17
17
to `fit(algorithm, (X, y))`.
18
18
19
19
!!! note
20
20
21
+ By default, it is assumed that `data` supports the [`LearnAPI.RandomAccess`](@ref)
22
+ interface; this includes all matrices, with observations-as-columns, most tables, and
23
+ tuples thereof). See [`LearnAPI.RandomAccess`](@ref) for details. If this is not the
24
+ case then an implementation must either:
25
+
21
26
If the `data` object consumed by `fit`, `predict`, or `transform` is not
22
27
not a suitable table¹, array³, tuple of tables and arrays, or some
23
28
other object implementing
24
29
the MLUtils.jl `getobs`/`numobs` interface,
25
- then an implementation must: (i) suitably overload the trait
26
- [`LearnAPI.data_interface`](@ref); and/or (ii) overload [`obs`](@ref), as
27
- illustrated below under [Providing an advanced data interface](@ref).
30
+ then an implementation must: (i) overload [`obs`](@ref) to articulate how
31
+ provided data can be transformed into a form that does support
32
+ it, as illustrated below under
33
+ [Providing an advanced data interface](@ref); or (ii) overload the trait
34
+ [`LearnAPI.data_interface`](@ref) to specify a more relaxed data
35
+ API.
28
36
29
37
The first line below imports the lightweight package LearnAPI.jl whose methods we will be
30
38
extending. The second imports libraries needed for the core algorithm.
@@ -152,9 +160,9 @@ from training data, by implementing [`LearnAPI.target`](@ref):
152
160
LearnAPI.target(algorithm, data) = last(data)
153
161
```
154
162
155
- There is a similar method, [ ` LearnAPI.input ` ] ( @ref ) for declaring how input data can be
156
- extracted (for passing to ` predict ` , for example) but this method has a fallback which
157
- typically suffices: return ` first(data) ` if ` data ` is a tuple, and otherwise return
163
+ There is a similar method, [ ` LearnAPI.features ` ] ( @ref ) for declaring how training features
164
+ can be extracted (for passing to ` predict ` , for example) but this method has a fallback
165
+ which typically suffices: return ` first(data) ` if ` data ` is a tuple, and otherwise return
158
166
` data ` .
159
167
160
168
@@ -218,7 +226,7 @@ A macro provides a shortcut, convenient when multiple traits are to be defined:
218
226
:(LearnAPI.algorithm),
219
227
:(LearnAPI.minimize),
220
228
:(LearnAPI.obs),
221
- :(LearnAPI.input ),
229
+ :(LearnAPI.features ),
222
230
:(LearnAPI.target),
223
231
:(LearnAPI.predict),
224
232
:(LearnAPI.coefficients),
@@ -325,7 +333,7 @@ LearnAPI.minimize(model::RidgeFitted) =
325
333
:(LearnAPI.algorithm),
326
334
:(LearnAPI.minimize),
327
335
:(LearnAPI.obs),
328
- :(LearnAPI.input ),
336
+ :(LearnAPI.features ),
329
337
:(LearnAPI.target),
330
338
:(LearnAPI.predict),
331
339
:(LearnAPI.coefficients),
@@ -423,7 +431,7 @@ LearnAPI.predict(model::RidgeFitted, ::LiteralTarget, Xnew) =
423
431
predict(model, LiteralTarget(), obs(model, Xnew))
424
432
```
425
433
426
- ### ` target ` and ` input ` methods
434
+ ### ` target ` and ` features ` methods
427
435
428
436
We provide an additional overloading of [ ` LearnAPI.target ` ] ( @ref ) to handle the additional
429
437
supported data argument of ` fit ` :
@@ -432,11 +440,11 @@ supported data argument of `fit`:
432
440
LearnAPI.target(::Ridge, observations::RidgeFitObs) = observations.y
433
441
```
434
442
435
- Similarly, we must overload [ ` LearnAPI.input ` ] ( @ref ) , which extracts inputs from training
436
- data (objects that can be passed to ` predict ` ) like this
443
+ Similarly, we must overload [ ` LearnAPI.features ` ] ( @ref ) , which extracts features from
444
+ training data (objects that can be passed to ` predict ` ) like this
437
445
438
446
``` @example anatomy2
439
- LearnAPI.input (::Ridge, observations::RidgeFitObs) = observations.A
447
+ LearnAPI.features (::Ridge, observations::RidgeFitObs) = observations.A
440
448
```
441
449
as the fallback mentioned above is no longer adequate.
442
450
@@ -482,6 +490,9 @@ ẑ = predict(model, MLUtils.getobs(observations_for_predict, test))
482
490
@assert ẑ == ŷ
483
491
```
484
492
493
+ For an application of [ ` obs ` ] ( @ref ) to efficient cross-validation, see [ here] (@ref
494
+ obs_workflows).
495
+
485
496
---
486
497
487
498
¹ In LearnAPI.jl a * table* is any object ` X ` implementing the
0 commit comments