Skip to content

Commit fae094c

Browse files
authored
Merge pull request #206 from JuliaAI/dev
Generate new docs.
2 parents 8107f2c + 7b7128f commit fae094c

File tree

4 files changed

+89
-29
lines changed

4 files changed

+89
-29
lines changed

docs/make.jl

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,30 @@ makedocs(;
1010
"Quick-start guide" => "quick_start_guide.md",
1111
"The model type hierarchy" => "the_model_type_hierarchy.md",
1212
"New model type declarations" => "type_declarations.md",
13-
"Supervised models" => "supervised_models.md",
14-
"Summary of methods" => "summary_of_methods.md",
15-
"The form of data for fitting and predicting" => "form_of_data.md",
16-
"The fit method" => "the_fit_method.md",
17-
"The fitted_params method" => "the_fitted_params_method.md",
18-
"The predict method" => "the_predict_method.md",
19-
"The predict_joint method" => "the_predict_joint_method.md",
20-
"Training losses" => "training_losses.md",
21-
"Feature importances" => "feature_importances.md",
22-
"Trait declarations" => "trait_declarations.md",
23-
"Iterative models and the update! method" => "iterative_models.md",
24-
"Implementing a data front end" => "implementing_a_data_front_end.md",
25-
"Supervised models with a transform method" =>
26-
"supervised_models_with_transform.md",
27-
"Models that learn a probability distribution" => "fitting_distributions.md",
28-
"Serialization" => "serialization.md",
29-
"Document strings" => "document_strings.md",
13+
"Supervised models" => [
14+
"Introduction" => "supervised_models.md",
15+
"Summary of methods" => "summary_of_methods.md",
16+
"The form of data for fitting and predicting" => "form_of_data.md",
17+
"The fit method" => "the_fit_method.md",
18+
"The fitted_params method" => "the_fitted_params_method.md",
19+
"The predict method" => "the_predict_method.md",
20+
"The predict_joint method" => "the_predict_joint_method.md",
21+
"Training losses" => "training_losses.md",
22+
"Feature importances" => "feature_importances.md",
23+
"Trait declarations" => "trait_declarations.md",
24+
"Iterative models and the update! method" => "iterative_models.md",
25+
"Implementing a data front end" => "implementing_a_data_front_end.md",
26+
"Supervised models with a transform method" =>
27+
"supervised_models_with_transform.md",
28+
"Models that learn a probability distribution" =>
29+
"fitting_distributions.md",
30+
],
3031
"Unsupervised models" => "unsupervised_models.md",
3132
"Static models" => "static_models.md",
3233
"Outlier detection models" => "outlier_detection_models.md",
34+
"Model wrappers" => "model_wrappers.md",
35+
"Serialization" => "serialization.md",
36+
"Document strings" => "document_strings.md",
3337
"Convenience methods" => "convenience_methods.md",
3438
"Where to place code implementing new models" => "where_to_put_code.md",
3539
"How to add models to the MLJ Model Registry" => "how_to_register.md",

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ API defined there, as outlined in this document.
88

99
!!! tip
1010

11-
This is a reference document, which has become rather sprawling over the evolution of the MLJ project. We recommend starting with [Quick start guide](@ref), which covers the main points relevant to most new model implementations.
11+
This is a reference document, which has become rather sprawling over the evolution of the MLJ project. We recommend starting with [Quick start guide](@ref), which covers the main points relevant to most new model implementations. Most topics are only detailed for `Supervised` models, so if you are implementing another kind of model, you may still need to refer to the [Supervised models](@ref) section.
1212

1313
Interface code can be hosted by the package providing the core machine learning algorithm,
1414
or by a stand-alone "interface-only" package, using the template

docs/src/model_wrappers.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Model wrappers
2+
3+
A model that can have one or more other models as hyper-parameters should overload the trait `is_wrapper`, as in this example:
4+
5+
```julia
6+
MLJModelInterface.target_in_fit(::Type{<:MyWrapper}) = true
7+
```
8+
9+
The constructor for such a model does not need provide default values for the model-valued
10+
hyper-parameters. If only a single model is wrapped, then the hyper-parameter should have
11+
the name `:model` and this should be an optional positional argument, as well as a keyword
12+
argument.
13+
14+
For example, `EnsembleModel` is a model wrapper, and we can construct an instance like this:
15+
16+
```julia
17+
using MLJ
18+
atom = ConstantClassfier()
19+
EnsembleModel(tree, n=100)
20+
```
21+
22+
but also like this:
23+
24+
```julia
25+
EnsembleModel(model=tree, n=100)
26+
```
27+
28+
This is the only case in MLJ where positional arguments in a model constructor are
29+
allowed.

docs/src/unsupervised_models.md

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ similar fashion. The main differences are:
55

66
- The `fit` method, which still returns `(fitresult, cache, report)` will typically have
77
only one training argument `X`, as in `MLJModelInterface.fit(model, verbosity, X)`,
8-
although this is not a hard requirement. For example, a feature selection tool (wrapping
9-
some supervised model) might also include a target `y` as input. Furthermore, in the
10-
case of models that subtype `Static <: Unsupervised` (see [Static
11-
models](@ref)) `fit` has no training arguments at all, but does not need to be
12-
implemented as a fallback returns `(nothing, nothing, nothing)`.
8+
although this is not a hard requirement; see [Transformers requiring a target variable
9+
in training](@ref) below. Furthermore, in the case of models that subtype `Static <:
10+
Unsupervised` (see [Static models](@ref)) `fit` has no training arguments at all, but
11+
does not need to be implemented as a fallback returns `(nothing, nothing, nothing)`.
1312

1413
- A `transform` and/or `predict` method is implemented, and has the same signature as
1514
`predict` does in the supervised case, as in `MLJModelInterface.transform(model,
@@ -27,15 +26,43 @@ similar fashion. The main differences are:
2726
argument, you must overload the trait `fit_data_scitype`, which bounds the allowed
2827
`data` passed to `fit(model, verbosity, data...)` and will always be a `Tuple` type.
2928

30-
- An `inverse_transform` can be optionally implemented. The signature
31-
is the same as `transform`, as in
32-
`MLJModelInterface.inverse_transform(model, fitresult, Xout)`, which:
29+
- An `inverse_transform` can be optionally implemented. The signature is the same as
30+
`transform`, as in `MLJModelInterface.inverse_transform(model::MyUnsupervisedModel,
31+
fitresult, Xout)`, which:
3332
- must make sense for any `Xout` for which `scitype(Xout) <:
34-
output_scitype(SomeSupervisedModel)` (see below); and
33+
output_scitype(MyUnsupervisedModel)`; and
3534
- must return an object `Xin` satisfying `scitype(Xin) <:
36-
input_scitype(SomeSupervisedModel)`.
35+
input_scitype(MyUnsupervisedModel)`.
3736

38-
For sample implementatations, see MLJ's [built-in
37+
For sample implementations, see MLJ's [built-in
3938
transformers](https://github.com/JuliaAI/MLJModels.jl/blob/dev/src/builtins/Transformers.jl)
4039
and the clustering models at
4140
[MLJClusteringInterface.jl](https://github.com/jbrea/MLJClusteringInterface.jl).
41+
42+
## Transformers requiring a target variable in training
43+
44+
An `Unsupervised` model that is not `Static` may include a second argument `y` in it's
45+
`fit` signature, as in `fit(::MyTransformer, verbosity, X, y)`. For example, some feature
46+
selection tools require a target variable `y` in training. (Unlike `Supervised` models, an
47+
`Unsupervised` model is not required to implement `predict`, and in pipelines it is the
48+
output of `transform`, and not `predict`, that is always propagated to the next model.) Such a
49+
model should overload the trait `target_in_fit`, as in this example:
50+
51+
```julia
52+
MLJModelInterface.target_in_fit(::Type{<:MyTransformer}) = true
53+
```
54+
55+
This ensures that such models can appear in pipelines, and that a target provided to the
56+
pipeline model is passed on to the model in training.
57+
58+
If the model implements more than one `fit` signature (e.g., one with a target `y` and one
59+
without) then `fit_data_scitype` must also be overloaded, as in this example:
60+
61+
```julia
62+
MLJModelInterface.fit_data_scitype(::Type{<:MyTransformer}) = Union{
63+
Tuple{Table(Continuous)},
64+
Tuple{Table(Continous), AbstractVector{<:Finite}},
65+
}
66+
```
67+
68+

0 commit comments

Comments
 (0)