@@ -38,7 +38,7 @@ weights(::Any, data) = nothing
38
38
39
39
Return, for each form of `data` supported in a call of the form [`fit(algorithm,
40
40
data)`](@ref), the "features" part of `data` (as opposed to the target
41
- variable, for example).
41
+ variable, for example).
42
42
43
43
The returned object `X` may always be passed to `predict` or `transform`, where
44
44
implemented, as in the following sample workflow:
@@ -49,28 +49,25 @@ X = features(data)
49
49
ŷ = predict(algorithm, kind_of_proxy, X) # eg, `kind_of_proxy = Point()`
50
50
```
51
51
52
- The return value has the same number of observations as `data` does . For supervised models
52
+ The returned object has the same number of observations as `data`. For supervised models
53
53
(i.e., where `:(LearnAPI.target) in LearnAPI.functions(algorithm)`) `ŷ` above is generally
54
54
intended to be an approximate proxy for `LearnAPI.target(algorithm, data)`, the training
55
55
target.
56
56
57
57
58
58
# New implementations
59
59
60
- The only contract `features` must satisfy is the one about passability of the output to
61
- `predict` or `transform`, for each supported input `data`. The following fallbacks
62
- typically make overloading `LearnAPI.features` unnecessary:
63
-
64
- ```julia
65
- LearnAPI.features(algorithm, data) = data
66
- LearnAPI.features(algorithm, data::Tuple) = first(data)
67
- ```
60
+ That the output can be passed to `predict` and/or `transform`, and has the same number of
61
+ observations as `data`, are the only contracts. A fallback returns `first(data)` if `data`
62
+ is a tuple, and otherwise returns `data`.
68
63
69
64
Overloading may be necessary if [`obs(algorithm, data)`](@ref) is overloaded to return
70
65
some algorithm-specific representation of training `data`. For density estimators, whose
71
66
`fit` typically consumes *only* a target variable, you should overload this method to
72
67
return `nothing`.
73
68
74
69
"""
75
- features (algorithm, data) = data
76
- features (algorithm, data:: Tuple ) = first (data)
70
+ features (algorithm, data) = _first (data)
71
+ _first (data) = data
72
+ _first (data:: Tuple ) = first (data)
73
+ # note the factoring above guards agains method ambiguities
0 commit comments