1
1
"""
2
- LearnAPI.target(learner, data ) -> target
2
+ LearnAPI.target(learner, observations ) -> target
3
3
4
- Return, for each form of `data` supported in a call of the form [`fit (learner,
5
- data)`](@ref), the target variable part of `data `. If `nothing` is returned, the
4
+ Return, for every conceivable `observations` returned by a call of the form [`obs (learner,
5
+ data)`](@ref), the target variable part of `observations `. If `nothing` is returned, the
6
6
`learner` does not see a target variable in training (is unsupervised).
7
7
8
- The returned object `y` has the same number of observations as `data`. If `data` is the
9
- output of an [`obs`](@ref) call, then `y` is additionally guaranteed to implement the
10
- data interface specified by [`LearnAPI.data_interface(learner)`](@ref).
8
+ The returned object `y` has the same number of observations as `observations` does and is
9
+ guaranteed to implement the data interface specified by
10
+ [`LearnAPI.data_interface(learner)`](@ref).
11
11
12
12
# Extended help
13
13
@@ -21,57 +21,61 @@ the LearnAPI.jl documentation.
21
21
22
22
## New implementations
23
23
24
- A fallback returns `nothing`. The method must be overloaded if `fit` consumes data
25
- including a target variable.
24
+ A fallback returns `nothing`. The method must be overloaded if [`fit`](@ref) consumes data
25
+ that includes a target variable. If `obs` is not being overloaded, then `observations`
26
+ above is any `data` supported in calls of the form [`fit(learner, data)`](@ref). The form
27
+ of the output `y` should be suitable for pairing with the output of [`predict`](@ref), in
28
+ the evaluation of a loss function, for example.
26
29
27
- If overloading [`obs`](@ref), ensure that the return value, unless `nothing`, implements
28
- the data interface specified by [`LearnAPI.data_interface(learner)`](@ref), in the special
29
- case that `data` is the output of an `obs` call.
30
+ Ensure the object `y` returned by `LearnAPI.target`, unless `nothing`, implements the data
31
+ interface specified by [`LearnAPI.data_interface(learner)`](@ref).
30
32
31
33
$(DOC_IMPLEMENTED_METHODS (" :(LearnAPI.target)" ; overloaded= true ))
32
34
33
35
"""
34
- target (:: Any , data ) = nothing
36
+ target (:: Any , observations ) = nothing
35
37
36
38
"""
37
- LearnAPI.weights(learner, data ) -> weights
39
+ LearnAPI.weights(learner, observations ) -> weights
38
40
39
- Return, for each form of `data` supported in a call of the form [`fit (learner,
40
- data)`](@ref), the per-observation weights part of `data `. Where `nothing` is returned, no
41
- weights are part of `data`, which is to be interpreted as uniform weighting.
41
+ Return, for every conceivable `observations` returned by a call of the form [`obs (learner,
42
+ data)`](@ref), the weights part of `observations `. Where `nothing` is returned, no weights
43
+ are part of `data`, which is to be interpreted as uniform weighting.
42
44
43
- The returned object `w` has the same number of observations as `data`. If `data` is the
44
- output of an [`obs`](@ref) call, then `w` is additionally guaranteed to implement the
45
- data interface specified by [`LearnAPI.data_interface(learner)`](@ref).
45
+ The returned object `w` has the same number of observations as `observations` does and is
46
+ guaranteed to implement the data interface specified by
47
+ [`LearnAPI.data_interface(learner)`](@ref).
46
48
47
49
# Extended help
48
50
49
51
# New implementations
50
52
51
- Overloading is optional. A fallback returns `nothing`.
53
+ Overloading is optional. A fallback returns `nothing`. If `obs` is not being overloaded,
54
+ then `observations` above is any `data` supported in calls of the form [`fit(learner,
55
+ data)`](@ref).
52
56
53
- If overloading [`obs`](@ref), ensure that the return value, unless `nothing`, implements
54
- the data interface specified by [`LearnAPI.data_interface(learner)`](@ref), in the special
55
- case that `data` is the output of an `obs` call.
57
+ Ensure the returned object, unless `nothing`, implements the data interface specified by
58
+ [`LearnAPI.data_interface(learner)`](@ref).
56
59
57
60
$(DOC_IMPLEMENTED_METHODS (" :(LearnAPI.weights)" ; overloaded= true ))
58
61
59
62
"""
60
- weights (:: Any , data ) = nothing
63
+ weights (:: Any , observations ) = nothing
61
64
62
65
"""
63
- LearnAPI.features(learner, data )
66
+ LearnAPI.features(learner, observations )
64
67
65
- Return, for each form of `data` supported in a call of the form [`fit (learner,
66
- data)`](@ref), the "features" part of `data` (as opposed to the target
67
- variable, for example).
68
+ Return, for every conceivable `observations` returned by a call of the form [`obs (learner,
69
+ data)`](@ref), the "features" part of `data` (as opposed to the target variable, for
70
+ example).
68
71
69
72
The returned object `X` may always be passed to `predict` or `transform`, where
70
73
implemented, as in the following sample workflow:
71
74
72
75
```julia
73
- model = fit(learner, data)
74
- X = LearnAPI.features(learner, data)
76
+ observations = obs(learner, data)
77
+ model = fit(learner, observations)
78
+ X = LearnAPI.features(learner, observations)
75
79
ŷ = predict(model, kind_of_proxy, X) # eg, `kind_of_proxy = Point()`
76
80
```
77
81
@@ -80,28 +84,30 @@ For supervised models (i.e., where `:(LearnAPI.target) in LearnAPI.functions(lea
80
84
data)`, the training target.
81
85
82
86
The object `X` returned by `LearnAPI.target` has the same number of observations as
83
- `data`. If `data` is the output of an [`obs`](@ref) call, then `X` is additionally
84
- guaranteed to implement the data interface specified by
87
+ `observations` does and is guaranteed to implement the data interface specified by
85
88
[`LearnAPI.data_interface(learner)`](@ref).
86
89
87
90
# Extended help
88
91
89
92
# New implementations
90
93
94
+ A fallback returns `first(observations)` if `observations` is a tuple, and otherwise
95
+ returns `observations`. New implementations may need to overload this method if this
96
+ fallback is inadequate.
97
+
91
98
For density estimators, whose `fit` typically consumes *only* a target variable, you
92
- should overload this method to return `nothing`.
99
+ should overload this method to return `nothing`. If `obs` is not being overloaded, then
100
+ `observations` above is any `data` supported in calls of the form [`fit(learner,
101
+ data)`](@ref).
93
102
94
103
It must otherwise be possible to pass the return value `X` to `predict` and/or
95
- `transform`, and `X` must have same number of observations as `data`. A fallback returns
96
- `first(data)` if `data` is a tuple, and otherwise returns `data`.
104
+ `transform`, and `X` must have same number of observations as `data`.
97
105
98
- Further overloadings may be necessary to handle the case that `data` is the output of
99
- [`obs(learner, data)`](@ref), if `obs` is being overloaded. In this case, be sure that
100
- `X`, unless `nothing`, implements the data interface specified by
106
+ Ensure the returned object, unless `nothing`, implements the data interface specified by
101
107
[`LearnAPI.data_interface(learner)`](@ref).
102
108
103
109
"""
104
- features (learner, data ) = _first (data )
105
- _first (data ) = data
106
- _first (data :: Tuple ) = first (data )
110
+ features (learner, observations ) = _first (observations )
111
+ _first (observations ) = observations
112
+ _first (observations :: Tuple ) = first (observations )
107
113
# note the factoring above guards against method ambiguities
0 commit comments