Skip to content

Commit 1b9808a

Browse files
committed
address review suggestion: add logging for update falling back to fit
1 parent 8323234 commit 1b9808a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/MLJDecisionTreeInterface.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ function MMI.update(
150150
only_iterations_have_changed = MMI.is_same_except(model, old_model, :n_trees)
151151

152152
if !only_iterations_have_changed
153+
verbosity > 0 && @info "Detected a change to hyperparameters " *
154+
"not restricted to `n_trees`. Recomputing $n_trees trees. "
153155
return MMI.fit(
154156
model,
155157
verbosity,

test/runtests.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,16 @@ end
281281
fit!(mach, verbosity=0)
282282
forest1_4 = fitted_params(mach).forest
283283
@test length(forest1_4) ==4
284+
285+
# increase n_trees:
284286
mach.model = $M(n_trees=7, rng = stable_rng())
285287
@test_logs(
286288
(:info, r""),
287289
(:info, r"Adding 3 trees"),
288290
fit!(mach, verbosity=1),
289291
)
292+
293+
# decrease n_trees:
290294
mach.model = $M(n_trees=5, rng = stable_rng())
291295
@test_logs(
292296
(:info, r""),
@@ -295,6 +299,16 @@ end
295299
)
296300
forest1_5 = fitted_params(mach).forest
297301
@test length(forest1_5) == 5
302+
303+
# change a different hyperparameter:
304+
mach.model = $M(n_trees=5, rng = stable_rng(), max_depth=1)
305+
@test_logs(
306+
(:info, r""),
307+
(:info, r"Detected"),
308+
fit!(mach, verbosity=1),
309+
)
310+
forest1_5_again = fitted_params(mach).forest
311+
@test length(forest1_5_again) == 5
298312
end |> eval
299313
end
300314
end

0 commit comments

Comments
 (0)