@@ -13,8 +13,8 @@ values, which themselves might be transparent.
13
13
Most objects of type `MLJType` are transparent.
14
14
15
15
```julia
16
- julia> params(EnsembleModel(atom =ConstantClassifier()))
17
- (atom = (target_type = Bool,),
16
+ julia> params(EnsembleModel(model =ConstantClassifier()))
17
+ (model = (target_type = Bool,),
18
18
weights = Float64[],
19
19
bagging_fraction = 0.8,
20
20
rng_seed = 0,
@@ -36,25 +36,42 @@ isnotaleaf(m::Model) = length(propertynames(m)) > 0
36
36
"""
37
37
flat_params(m::Model)
38
38
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 .
43
43
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
+ ```
46
67
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,)
54
68
55
69
"""
56
70
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
58
75
function flat_params (m, :: Val{true} ; prefix= " " )
59
76
fields = propertynames (m)
60
77
prefix = prefix == " " ? " " : prefix * " __"
0 commit comments