Skip to content

Commit

Permalink
Merge pull request #880 from JuliaAI/dev
Browse files Browse the repository at this point in the history
For a 0.21.5 release
  • Loading branch information
ablaom authored Jan 27, 2023
2 parents e5084b7 + cba51a3 commit c51e789
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MLJBase"
uuid = "a7f614a8-145f-11e9-1d2a-a57a1082229d"
authors = ["Anthony D. Blaom <[email protected]>"]
version = "0.21.4"
version = "0.21.5"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
Expand Down
13 changes: 12 additions & 1 deletion src/composition/learning_networks/signatures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ single machine.
function machines_given_model(node::AbstractNode)
ret = LittleDict{Symbol,Any}()
for mach in machines(node)
model = mach.model
model = mach.model
model isa Symbol || continue
if !haskey(ret, model)
ret[model] = Any[mach,]
Expand Down Expand Up @@ -245,6 +245,17 @@ See also [`MLJBase.Signature`](@ref).
"""
operations(signature::Signature) = keys(operation_nodes(signature))

"""
glb(signature::Signature)
**Private method.**
Return the greatest lower bound of all operation nodes, report nodes and fitted parameter
nodes associated with `signature`.
See also [`MLJBase.Signature`](@ref).
"""
function glb(signature::Signature)
grab(f) = values(f(signature)) |> collect
nodes = vcat(
Expand Down
25 changes: 24 additions & 1 deletion src/composition/models/stacking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,28 @@ const ERR_BAD_METALEARNER = ArgumentError(
"of $(Union{Deterministic, Probabilistic})"
)

ERR_BAD_BASEMODEL(model) = ArgumentError(
"The base model $model is not supported as it appears to "*
"be a classifier predicting point values. Ordinarily, the "*
"the model must either be a "*
"probabilistic classifier (output of `predict` is a vector of "*
"`UnivariateFinite`) "*
"or a regressor (`target_scitype(model) <: "*
"AbstractVector{<:Union{Continuous,Missing}}`). "
)

const ERR_NO_METALEARNER = ArgumentError(
"No metalearner specified. Use Stack(metalearner=..., model1=..., model2=...)"
)

# checks `model` is either a probabilistic classifier or a regressor:
function check_valid_basemodel(model)
problem = prediction_type(model) === :deterministic &&
target_scitype(model) <: AbstractVector{<:Union{Finite,Missing}}
problem && throw(ERR_BAD_BASEMODEL(model))
return nothing
end

mutable struct DeterministicStack{
modelnames,
inp_scitype,
Expand Down Expand Up @@ -179,8 +197,13 @@ function MMI.clean!(stack::Stack{modelnames, inp_scitype, tg_scitype}) where {
tg_scitype
}

# We only carry checks and don't try to correct the arguments here
# We only carry out checks and don't try to correct the arguments here
message = ""

# check basemodels:
basemodels = map(name -> getproperty(stack, name), modelnames)
check_valid_basemodel.(basemodels)

# Checking target_scitype and input_scitype have not been changed from the original
# stack:
glb_inp_scitype, glb_tg_scitype =
Expand Down
2 changes: 1 addition & 1 deletion src/machines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ A machine returned by `serializable` is characterized by the property
# This machine can now be serialized
smach = serializable(mach)
JLSO.save("machine.jlso", machine => smach)
JLSO.save("machine.jlso", :machine => smach)
# Deserialize and restore learned parameters to useable form:
loaded_mach = JLSO.load("machine.jlso")[:machine]
Expand Down
9 changes: 5 additions & 4 deletions src/show.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
## REGISTERING LABELS OF OBJECTS DURING ASSIGNMENT

"""
color_on()
Expand All @@ -20,6 +18,8 @@ macro colon(p)
Expr(:quote, p)
end

## REGISTERING LABELS OF OBJECTS DURING ASSIGNMENT

"""
@constant x = value
Expand Down Expand Up @@ -70,8 +70,9 @@ end

# long version of showing a named tuple:
Base.show(stream::IO, ::MIME"text/plain", t::NamedTuple) = fancy_nt(stream, t)
fancy_nt(t) = fancy_nt(stdout, t)
fancy_nt(stream::IO, t) = fancy_nt(stream, t, 0)
fancy_nt(t) = fancy_nt(stdout, t) # is this used?
fancy_nt(stream, t::NamedTuple{(), Tuple{}}) = print(stream, "NamedTuple()")
fancy_nt(stream, t) = fancy_nt(stream, t, 0)
fancy_nt(stream, t, n) = show(stream, t)
function fancy_nt(stream, t::NamedTuple, n)
print(stream, "(")
Expand Down
7 changes: 7 additions & 0 deletions test/composition/models/stacking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ end
end

@testset "Stack constructor valid argument checks" begin

# baselearner cannot be a deterministic classifier:
@test_throws(
MLJBase.ERR_BAD_BASEMODEL(DeterministicConstantClassifier()),
Stack(metalearner=ConstantClassifier(), mymodel=DeterministicConstantClassifier()),
)

# metalearner should be `Deterministic` or `Probablisitic`:
@test_throws(
MLJBase.ERR_BAD_METALEARNER,
Expand Down

0 comments on commit c51e789

Please sign in to comment.