Closed ablaom closed 10 months ago
@ablaom I just identified this problem in our code. The way we are identifying and returning leaf values is not correct. This issue is coming from MLJModelInterface.
isnotaleaf(::Any) = false
isnotaleaf(m::Model) = length(propertynames(m)) > 0
flat_params(m, ::Val{false}; prefix="") = NamedTuple{(Symbol(prefix),), Tuple{Any}}((m,))
When we pass the ConstantClassifier()
(or any zero params model), isnotaleaf
is returning false. From flat_params(...)
, our result is ( = ConstantClassifier(),)
. That's the source of our problem.
The simplest way to solve this is to perform a validation, but maybe there is a better way to do that.
@pebeto Thanks for the diagnosis. I've made the PR referenced above to give flat_params
expected behaviour: flat_params(ConstantClassifier())
should return an empty tuple NamedTuple()
. Can you please review?
@pebeto That PR has been merged. How should we proceed?
@ablaom, must we throw an error if the model contains zero parameters? Now we are logging the model without issues.
I wouldn't throw an error if it is working as expected.
ConstantClassifier
is a model with no hyperparameters. If I changeConstantClassifer
below toDecisionTreeClassifier
, for example, then no error is thrown.