Skip to content

Commit 266ef8e

Browse files
authored
Merge pull request #183 from JuliaAI/dev
For a 1.9.3 release
2 parents ad82652 + 9736531 commit 266ef8e

File tree

4 files changed

+43
-17
lines changed

4 files changed

+43
-17
lines changed

.github/codecov.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
threshold: 0.5%

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MLJModelInterface"
22
uuid = "e80e1ace-859a-464e-9ed9-23947d8ae3ea"
33
authors = ["Thibaut Lienart and Anthony Blaom"]
4-
version = "1.9.2"
4+
version = "1.9.3"
55

66
[deps]
77
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

src/parameter_inspection.jl

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ values, which themselves might be transparent.
1313
Most objects of type `MLJType` are transparent.
1414
1515
```julia
16-
julia> params(EnsembleModel(atom=ConstantClassifier()))
17-
(atom = (target_type = Bool,),
16+
julia> params(EnsembleModel(model=ConstantClassifier()))
17+
(model = (target_type = Bool,),
1818
weights = Float64[],
1919
bagging_fraction = 0.8,
2020
rng_seed = 0,
@@ -36,25 +36,42 @@ isnotaleaf(m::Model) = length(propertynames(m)) > 0
3636
"""
3737
flat_params(m::Model)
3838
39-
Recursively convert any object subtyping `Model` into a named tuple, keyed on
40-
the property names of `m`. The named tuple is possibly nested because
41-
`flat_params` is recursively applied to the property values, which themselves
42-
might subtype `Model`.
39+
Deconstruct any `Model` instance `model` as a flat named tuple, keyed on property
40+
names. Properties of nested model instances are recursively exposed,.as shown in the
41+
example below. For most `Model` objects, properties are synonymous with fields, but this
42+
is not a hard requirement.
4343
44-
For most `Model` objects, properties are synonymous with fields, but this is
45-
not a hard requirement.
44+
```julia
45+
using MLJModels
46+
using EnsembleModels
47+
tree = (@load DecisionTreeClassifier pkg=DecisionTree)
48+
49+
julia> flat_params(EnsembleModel(model=tree))
50+
(model__max_depth = -1,
51+
model__min_samples_leaf = 1,
52+
model__min_samples_split = 2,
53+
model__min_purity_increase = 0.0,
54+
model__n_subfeatures = 0,
55+
model__post_prune = false,
56+
model__merge_purity_threshold = 1.0,
57+
model__display_depth = 5,
58+
model__feature_importance = :impurity,
59+
model__rng = Random._GLOBAL_RNG(),
60+
atomic_weights = Float64[],
61+
bagging_fraction = 0.8,
62+
rng = Random._GLOBAL_RNG(),
63+
n = 100,
64+
acceleration = CPU1{Nothing}(nothing),
65+
out_of_bag_measure = Any[],)
66+
```
4667
47-
julia> flat_params(EnsembleModel(atom=ConstantClassifier()))
48-
(atom = (target_type = Bool,),
49-
weights = Float64[],
50-
bagging_fraction = 0.8,
51-
rng_seed = 0,
52-
n = 100,
53-
parallel = true,)
5468
5569
"""
5670
flat_params(m; prefix="") = flat_params(m, Val(isnotaleaf(m)); prefix=prefix)
57-
flat_params(m, ::Val{false}; prefix="") = NamedTuple{(Symbol(prefix),), Tuple{Any}}((m,))
71+
function flat_params(m, ::Val{false}; prefix="")
72+
prefix == "" && return NamedTuple()
73+
NamedTuple{(Symbol(prefix),), Tuple{Any}}((m,))
74+
end
5875
function flat_params(m, ::Val{true}; prefix="")
5976
fields = propertynames(m)
6077
prefix = prefix == "" ? "" : prefix * "__"

test/parameter_inspection.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ end
4848

4949
struct Missy <: Model end
5050

51+
struct EmptyModel <: Model end
52+
5153
@testset "flat_params method" begin
5254

5355
m = ParentModel(1, "parent", ChildModel(2, "child1"),
@@ -61,5 +63,7 @@ struct Missy <: Model end
6163
second_child__r = 3,
6264
second_child__s = Missy()
6365
)
66+
67+
@test MLJModelInterface.flat_params(EmptyModel()) == NamedTuple()
6468
end
6569
true

0 commit comments

Comments
 (0)