From 19fe38b74c51e1d93b4dc1ed006dd3e606498f99 Mon Sep 17 00:00:00 2001 From: "Anthony D. Blaom" Date: Fri, 31 May 2024 09:11:34 +1200 Subject: [PATCH 1/4] bump 1.4.0 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 181d50af..0c339e9e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MLJBase" uuid = "a7f614a8-145f-11e9-1d2a-a57a1082229d" authors = ["Anthony D. Blaom "] -version = "1.3" +version = "1.4.0" [deps] CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597" From 4e9d58105a9bdc8c118cfe6292d4a9e60942a836 Mon Sep 17 00:00:00 2001 From: "Anthony D. Blaom" Date: Fri, 31 May 2024 09:13:45 +1200 Subject: [PATCH 2/4] bump [compat] MLJModelInterface = "1.10"; StatisticalTraits = "3.4" --- Project.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 0c339e9e..b2efe10a 100644 --- a/Project.toml +++ b/Project.toml @@ -47,7 +47,7 @@ DelimitedFiles = "1" Distributions = "0.25.3" InvertedIndices = "1" LearnAPI = "0.1" -MLJModelInterface = "1.7" +MLJModelInterface = "1.10" Missings = "0.4, 1" OrderedCollections = "1.1" Parameters = "0.12" @@ -58,7 +58,7 @@ Reexport = "1.2" ScientificTypes = "3" StatisticalMeasures = "0.1.1" StatisticalMeasuresBase = "0.1.1" -StatisticalTraits = "3.2" +StatisticalTraits = "3.4" Statistics = "1" StatsBase = "0.32, 0.33, 0.34" Tables = "0.2, 1.0" From bdb9cfc4159a0534f4da02ef5ecfaa37e50008f9 Mon Sep 17 00:00:00 2001 From: "Anthony D. Blaom" Date: Mon, 3 Jun 2024 16:20:22 +1200 Subject: [PATCH 3/4] oops; change [compat] StatisticalTraits = "3.3" --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index b2efe10a..39ebba98 100644 --- a/Project.toml +++ b/Project.toml @@ -58,7 +58,7 @@ Reexport = "1.2" ScientificTypes = "3" StatisticalMeasures = "0.1.1" StatisticalMeasuresBase = "0.1.1" -StatisticalTraits = "3.4" +StatisticalTraits = "3.3" Statistics = "1" StatsBase = "0.32, 0.33, 0.34" Tables = "0.2, 1.0" From 52d16df186282878be8a0c8d8a4d80da7a93dbac Mon Sep 17 00:00:00 2001 From: "Anthony D. Blaom" Date: Mon, 3 Jun 2024 16:21:02 +1200 Subject: [PATCH 4/4] implement constructor trait for wrappers --- src/composition/models/pipelines.jl | 3 +++ src/composition/models/stacking.jl | 7 ++--- .../models/transformed_target_model.jl | 7 ++++- src/resampling.jl | 27 +++++++++---------- test/composition/models/pipelines.jl | 4 ++- test/composition/models/stacking.jl | 3 +++ .../models/transformed_target_model.jl | 1 + test/resampling.jl | 3 +++ 8 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/composition/models/pipelines.jl b/src/composition/models/pipelines.jl index 41d165cb..0ea85297 100644 --- a/src/composition/models/pipelines.jl +++ b/src/composition/models/pipelines.jl @@ -599,6 +599,9 @@ end MMI.target_scitype(p::SupervisedPipeline) = target_scitype(supervised_component(p)) +MMI.package_name(::Type{<:SomePipeline}) = "MLJBase" +MMI.load_path(::Type{<:SomePipeline}) = "MLJBase.Pipeline" +MMI.constructor(::Type{<:SomePipeline}) = Pipeline # ## Training losses diff --git a/src/composition/models/stacking.jl b/src/composition/models/stacking.jl index 7de00112..70be5041 100644 --- a/src/composition/models/stacking.jl +++ b/src/composition/models/stacking.jl @@ -264,6 +264,8 @@ function Base.setproperty!(stack::Stack{modelnames}, _name::Symbol, val) where m end +# # TRAITS + MMI.target_scitype(::Type{<:Stack{modelnames, input_scitype, target_scitype}}) where {modelnames, input_scitype, target_scitype} = target_scitype @@ -271,9 +273,8 @@ MMI.target_scitype(::Type{<:Stack{modelnames, input_scitype, target_scitype}}) w MMI.input_scitype(::Type{<:Stack{modelnames, input_scitype, target_scitype}}) where {modelnames, input_scitype, target_scitype} = input_scitype - -MLJBase.load_path(::Type{<:ProbabilisticStack}) = "MLJBase.ProbabilisticStack" -MLJBase.load_path(::Type{<:DeterministicStack}) = "MLJBase.DeterministicStack" +MMI.constructor(::Type{<:Stack}) = Stack +MLJBase.load_path(::Type{<:Stack}) = "MLJBase.Stack" MLJBase.package_name(::Type{<:Stack}) = "MLJBase" MLJBase.package_uuid(::Type{<:Stack}) = "a7f614a8-145f-11e9-1d2a-a57a1082229d" MLJBase.package_url(::Type{<:Stack}) = "https://github.com/JuliaAI/MLJBase.jl" diff --git a/src/composition/models/transformed_target_model.jl b/src/composition/models/transformed_target_model.jl index 9304b63c..272b226e 100644 --- a/src/composition/models/transformed_target_model.jl +++ b/src/composition/models/transformed_target_model.jl @@ -10,7 +10,8 @@ const TT_SUPPORTED_ATOMS = ( :Deterministic, :DeterministicUnsupervisedDetector, :DeterministicSupervisedDetector, - :Interval) + :Interval, +) # Each supported atomic type gets its own wrapper: @@ -265,6 +266,10 @@ MMI.package_uuid(::Type{<:SomeTT}) = "a7f614a8-145f-11e9-1d2a-a57a1082229d" MMI.is_wrapper(::Type{<:SomeTT}) = true MMI.package_url(::Type{<:SomeTT}) = "https://github.com/JuliaAI/MLJBase.jl" +MMI.load_path(::Type{<:SomeTT}) = "MLJBase.TransformedTargetModel" +MMI.constructor(::Type{<:SomeTT}) = TransformedTargetModel + + for New in TT_TYPE_EXS quote MMI.iteration_parameter(::Type{<:$New{M}}) where M = diff --git a/src/resampling.jl b/src/resampling.jl index 250e3ca0..68ecc040 100644 --- a/src/resampling.jl +++ b/src/resampling.jl @@ -1548,9 +1548,11 @@ end compact=false, ) +*Private method.* Use at own risk. + Resampling model wrapper, used internally by the `fit` method of `TunedModel` instances -and `IteratedModel` instances. See [`evaluate!](@ref) for options. Not intended for use by -general user, who will ordinarily use [`evaluate!`](@ref) directly. +and `IteratedModel` instances. See [`evaluate!`](@ref) for meaning of the options. Not +intended for use by general user, who will ordinarily use [`evaluate!`](@ref) directly. Given a machine `mach = machine(resampler, args...)` one obtains a performance evaluation of the specified `model`, performed according to the prescribed `resampling` strategy and @@ -1592,16 +1594,6 @@ mutable struct Resampler{S, L} <: Model compact::Bool end -# Some traits are markded as `missing` because we cannot determine -# them from from the type because we have removed `M` (for "model"} as -# a `Resampler` type parameter. See -# https://github.com/JuliaAI/MLJTuning.jl/issues/141#issue-951221466 - -StatisticalTraits.is_wrapper(::Type{<:Resampler}) = true -StatisticalTraits.supports_weights(::Type{<:Resampler}) = missing -StatisticalTraits.supports_class_weights(::Type{<:Resampler}) = missing -StatisticalTraits.is_pure_julia(::Type{<:Resampler}) = true - function MLJModelInterface.clean!(resampler::Resampler) warning = "" if resampler.measure === nothing && resampler.model !== nothing @@ -1787,11 +1779,16 @@ function MLJModelInterface.update( end -# The input and target scitypes cannot be determined from the type -# because we have removed `M` (for "model") as a `Resampler` type -# parameter. See +# Some traits are marked as `missing` because we cannot determine +# them from from the type because we have removed `M` (for "model"} as +# a `Resampler` type parameter. See # https://github.com/JuliaAI/MLJTuning.jl/issues/141#issue-951221466 +StatisticalTraits.is_wrapper(::Type{<:Resampler}) = true +StatisticalTraits.supports_weights(::Type{<:Resampler}) = missing +StatisticalTraits.supports_class_weights(::Type{<:Resampler}) = missing +StatisticalTraits.is_pure_julia(::Type{<:Resampler}) = true +StatisticalTraits.constructor(::Type{<:Resampler}) = Resampler StatisticalTraits.input_scitype(::Type{<:Resampler}) = Unknown StatisticalTraits.target_scitype(::Type{<:Resampler}) = Unknown StatisticalTraits.package_name(::Type{<:Resampler}) = "MLJBase" diff --git a/test/composition/models/pipelines.jl b/test/composition/models/pipelines.jl index d8790f09..e213cdc2 100644 --- a/test/composition/models/pipelines.jl +++ b/test/composition/models/pipelines.jl @@ -95,7 +95,9 @@ end @testset "public constructor" begin # un-named components: - @test Pipeline(m, t, u) isa UnsupervisedPipeline + flute = Pipeline(m, t, u) + @test flute isa UnsupervisedPipeline + @test MLJBase.constructor(flute) == Pipeline @test Pipeline(m, t, u, p) isa ProbabilisticPipeline @test Pipeline(m, t, u, p, operation=predict_mean) isa DeterministicPipeline @test Pipeline(u, p, u, operation=predict_mean) isa DeterministicPipeline diff --git a/test/composition/models/stacking.jl b/test/composition/models/stacking.jl index ca973775..110ccdef 100644 --- a/test/composition/models/stacking.jl +++ b/test/composition/models/stacking.jl @@ -202,6 +202,9 @@ end measures=rmse, resampling=CV(;nfolds=3), models...) + + @test MLJBase.constructor(mystack) == Stack + @test mystack.ridge_lambda.lambda == 0.1 @test mystack.metalearner isa FooBarRegressor @test mystack.resampling isa CV diff --git a/test/composition/models/transformed_target_model.jl b/test/composition/models/transformed_target_model.jl index b992503c..e3435542 100644 --- a/test/composition/models/transformed_target_model.jl +++ b/test/composition/models/transformed_target_model.jl @@ -86,6 +86,7 @@ avg_nonlinear = g(mean(f(y))) # = g(mean(z)) # Test wrapping using f and g: model = TransformedTargetModel(atom, transformer=f, inverse=g) + @test MLJBase.constructor(model) == TransformedTargetModel fr1, _, _ = MMI.fit(model, 0, X, y) @test first(predict(model, fr1, X)) ≈ fill(avg_nonlinear, 5) diff --git a/test/resampling.jl b/test/resampling.jl index 19b35165..33ee41ec 100644 --- a/test/resampling.jl +++ b/test/resampling.jl @@ -606,6 +606,9 @@ end holdout = Holdout(fraction_train=0.75) resampler = Resampler(resampling=holdout, model=ridge_model, measure=mae, acceleration=accel) + @test constructor(resampler) == Resampler + @test package_name(resampler) == "MLJBase" + @test load_path(resampler) == "MLJBase.Resampler" resampling_machine = machine(resampler, X, y) @test_logs((:info, r"^Training"), fit!(resampling_machine)) e1=evaluate(resampling_machine).measurement[1]