Skip to content

Commit ba24242

Browse files
authored
Merge pull request #37 from JuliaAI/unknown-in-pkg-name
Re-organize code to resolve docstring bug
2 parents 21fce28 + 89c8479 commit ba24242

5 files changed

Lines changed: 88 additions & 81 deletions

File tree

src/FeatureSelection.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ const MMI = MLJModelInterface
1010
include("models/featureselector.jl")
1111
include("models/rfe.jl")
1212
include("shared.jl")
13+
include("type_docstrings.jl")
1314

1415
end # module

src/models/featureselector.jl

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -87,82 +87,4 @@ MMI.metadata_model(
8787
load_path = "FeatureSelection.FeatureSelector"
8888
)
8989

90-
## Docstring
91-
"""
92-
$(MMI.doc_header(FeatureSelector))
93-
94-
Use this model to select features (columns) of a table, usually as
95-
part of a model `Pipeline`.
96-
97-
98-
# Training data
99-
100-
In MLJ or MLJBase, bind an instance `model` to data with
101-
102-
mach = machine(model, X)
103-
104-
where
105-
106-
- `X`: any table of input features, where "table" is in the sense of Tables.jl
107-
108-
Train the machine using `fit!(mach, rows=...)`.
109-
110-
111-
# Hyper-parameters
112-
113-
- `features`: one of the following, with the behavior indicated:
114-
115-
- `[]` (empty, the default): filter out all features (columns) which
116-
were not encountered in training
117-
118-
- non-empty vector of feature names (symbols): keep only the
119-
specified features (`ignore=false`) or keep only unspecified
120-
features (`ignore=true`)
121-
122-
- function or other callable: keep a feature if the callable returns
123-
`true` on its name. For example, specifying
124-
`FeatureSelector(features = name -> name in [:x1, :x3], ignore =
125-
true)` has the same effect as `FeatureSelector(features = [:x1,
126-
:x3], ignore = true)`, namely to select all features, with the
127-
exception of `:x1` and `:x3`.
128-
129-
- `ignore`: whether to ignore or keep specified `features`, as
130-
explained above
131-
132-
133-
# Operations
134-
135-
- `transform(mach, Xnew)`: select features from the table `Xnew` as
136-
specified by the model, taking features seen during training into
137-
account, if relevant
138-
139-
140-
# Fitted parameters
141-
142-
The fields of `fitted_params(mach)` are:
143-
144-
- `features_to_keep`: the features that will be selected
145-
146-
147-
# Example
148-
149-
```
150-
using MLJ
151-
152-
X = (ordinal1 = [1, 2, 3],
153-
ordinal2 = coerce(["x", "y", "x"], OrderedFactor),
154-
ordinal3 = [10.0, 20.0, 30.0],
155-
ordinal4 = [-20.0, -30.0, -40.0],
156-
nominal = coerce(["Your father", "he", "is"], Multiclass));
157-
158-
selector = FeatureSelector(features=[:ordinal3, ], ignore=true);
159-
160-
julia> transform(fit!(machine(selector, X)), X)
161-
(ordinal1 = [1, 2, 3],
162-
ordinal2 = CategoricalValue{Symbol,UInt32}["x", "y", "x"],
163-
ordinal4 = [-20.0, -30.0, -40.0],
164-
nominal = CategoricalValue{String,UInt32}["Your father", "he", "is"],)
165-
166-
```
167-
"""
168-
FeatureSelector
90+
# docstring is in "src/type_docstrings.jl"

src/type_docstrings.jl

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# This file cannot be include before types and all metadata is defined
2+
3+
## Docstring
4+
"""
5+
$(MMI.doc_header(FeatureSelector))
6+
7+
Use this model to select features (columns) of a table, usually as
8+
part of a model `Pipeline`.
9+
10+
11+
# Training data
12+
13+
In MLJ or MLJBase, bind an instance `model` to data with
14+
15+
mach = machine(model, X)
16+
17+
where
18+
19+
- `X`: any table of input features, where "table" is in the sense of Tables.jl
20+
21+
Train the machine using `fit!(mach, rows=...)`.
22+
23+
24+
# Hyper-parameters
25+
26+
- `features`: one of the following, with the behavior indicated:
27+
28+
- `[]` (empty, the default): filter out all features (columns) which
29+
were not encountered in training
30+
31+
- non-empty vector of feature names (symbols): keep only the
32+
specified features (`ignore=false`) or keep only unspecified
33+
features (`ignore=true`)
34+
35+
- function or other callable: keep a feature if the callable returns
36+
`true` on its name. For example, specifying
37+
`FeatureSelector(features = name -> name in [:x1, :x3], ignore =
38+
true)` has the same effect as `FeatureSelector(features = [:x1,
39+
:x3], ignore = true)`, namely to select all features, with the
40+
exception of `:x1` and `:x3`.
41+
42+
- `ignore`: whether to ignore or keep specified `features`, as
43+
explained above
44+
45+
46+
# Operations
47+
48+
- `transform(mach, Xnew)`: select features from the table `Xnew` as
49+
specified by the model, taking features seen during training into
50+
account, if relevant
51+
52+
53+
# Fitted parameters
54+
55+
The fields of `fitted_params(mach)` are:
56+
57+
- `features_to_keep`: the features that will be selected
58+
59+
60+
# Example
61+
62+
```
63+
using MLJ
64+
65+
X = (ordinal1 = [1, 2, 3],
66+
ordinal2 = coerce(["x", "y", "x"], OrderedFactor),
67+
ordinal3 = [10.0, 20.0, 30.0],
68+
ordinal4 = [-20.0, -30.0, -40.0],
69+
nominal = coerce(["Your father", "he", "is"], Multiclass));
70+
71+
selector = FeatureSelector(features=[:ordinal3, ], ignore=true);
72+
73+
julia> transform(fit!(machine(selector, X)), X)
74+
(ordinal1 = [1, 2, 3],
75+
ordinal2 = CategoricalValue{Symbol,UInt32}["x", "y", "x"],
76+
ordinal4 = [-20.0, -30.0, -40.0],
77+
nominal = CategoricalValue{String,UInt32}["Your father", "he", "is"],)
78+
79+
```
80+
"""
81+
FeatureSelector

test/models/featureselector.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
# Test model Metadata
6363
@test MLJBase.input_scitype(selector) == MLJBase.Table
6464
@test MLJBase.output_scitype(selector) == MLJBase.Table
65+
@test MLJBase.package_name(selector) == "FeatureSelection"
6566
end
6667

6768
# To be added with FeatureSelectorRule X = (n1=["a", "b", "a"], n2=["g", "g", "g"], n3=[7, 8, 9],

test/models/rfe.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,10 @@ const DTM = DummyTestModels
106106
# Traits
107107
@test MLJBase.package_name(selector) == "FeatureSelection"
108108
@test MLJBase.load_path(selector) == "FeatureSelection.RecursiveFeatureElimination"
109-
@test MLJBase.iteration_parameter(selector) == FeatureSelection.prepend(:model, MLJBase.iteration_parameter(selector.model))
110-
@test MLJBase.training_losses(selector, rpt) == MLJBase.training_losses(selector.model, rpt.model_report)
109+
@test MLJBase.iteration_parameter(selector) ==
110+
FeatureSelection.prepend(:model, MLJBase.iteration_parameter(selector.model))
111+
@test MLJBase.training_losses(selector, rpt) ==
112+
MLJBase.training_losses(selector.model, rpt.model_report)
111113
end
112114

113115
@testset "Compare results for RFE with scikit-learn" begin

0 commit comments

Comments
 (0)