Skip to content

Commit

Permalink
make MLJBase.default_logger() the default logger in TunedModel(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
ablaom committed Jun 25, 2024
1 parent 33baca3 commit e6fac32
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/tuned_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ key | value
regular [`PerformanceEvaluation`](@ref) objects to the history (accessed via the
`:evaluation` key); the compact form excludes some fields to conserve memory.
- `logger=default_logger()`: a logger for externally reporting model performance
evaluations, such as an `MLJFlow.Logger` instance. On startup,
`default_logger()=nothing`; use `default_logger(logger)` to set a global logger.
"""
function TunedModel(
args...;
Expand All @@ -281,7 +285,7 @@ function TunedModel(
check_measure=true,
cache=true,
compact_history=true,
logger=nothing
logger=MLJBase.default_logger()
)

# user can specify model as argument instead of kwarg:
Expand Down
25 changes: 25 additions & 0 deletions test/tuned_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -526,4 +526,29 @@ end
@test first(evaluations) isa MLJBase.PerformanceEvaluation
end

struct DummyLogger
buffer
end

MLJBase.log_evaluation(logger::DummyLogger, performance_evaluation) =
write(logger.buffer, performance_evaluation.measurement[1])

@testset "default logger" begin
buffer = IOBuffer()
logger = DummyLogger(buffer)
default_logger(logger)
model1 = KNNRegressor(K=5)
model2 = KNNRegressor(K=3)
tmodel = TunedModel(models=[model1, model2], measure=l2)
mach = machine(tmodel, make_regression(10)...)
fit!(mach, verbosity=0)
seekstart(buffer)
@test all(report(mach).history) do entry
logger_measurement = read(buffer, Float64)
logger_measurement == entry.evaluation.measurement[1]
end
default_logger(nothing)
close(buffer)
end

true

0 comments on commit e6fac32

Please sign in to comment.