Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the global default_logger() the default logger in TunedModel(logger=...) #221

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MLJTuning"
uuid = "03970b2e-30c4-11ea-3135-d1576263f10f"
authors = ["Anthony D. Blaom <[email protected]>"]
version = "0.8.7"
version = "0.8.8"

[deps]
ComputationalResources = "ed09eef8-17a6-5b46-8889-db040fac31e3"
Expand All @@ -18,7 +18,7 @@ StatisticalMeasuresBase = "c062fc1d-0d66-479b-b6ac-8b44719de4cc"
ComputationalResources = "0.3"
Distributions = "0.22,0.23,0.24, 0.25"
LatinHypercubeSampling = "1.7.2"
MLJBase = "1.4"
MLJBase = "1.5"
ProgressMeter = "1.7.1"
RecipesBase = "0.8,0.9,1"
StatisticalMeasuresBase = "0.1.1"
Expand Down
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
Loading