Skip to content

Commit

Permalink
Merge pull request #191 from JuliaAI/update-learning-network-use-in-t…
Browse files Browse the repository at this point in the history
…ests

Fix some tests that use deprecated MLJBase code
  • Loading branch information
ablaom authored Aug 9, 2023
2 parents 87f370a + 38e79d2 commit 6a15fb5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
19 changes: 11 additions & 8 deletions test/models/simple_composite_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ intended for internal testing .
"""
mutable struct SimpleDeterministicCompositeModel{L<:Deterministic,
T<:Unsupervised} <: DeterministicComposite
T<:Unsupervised} <: DeterministicNetworkComposite
model::L
transformer::T

Expand All @@ -33,20 +33,23 @@ end

MLJBase.is_wrapper(::Type{<:SimpleDeterministicCompositeModel}) = true

function MLJBase.fit(composite::SimpleDeterministicCompositeModel,
verbosity::Integer, Xtrain, ytrain)
function MLJBase.prefit(
composite::SimpleDeterministicCompositeModel,
verbosity,
Xtrain,
ytrain,
)

X = source(Xtrain) # instantiates a source node
y = source(ytrain)

t = machine(composite.transformer, X)
t = machine(:transformer, X)
Xt = transform(t, X)

l = machine(composite.model, Xt, y)
l = machine(:model, Xt, y)
yhat = predict(l, Xt)

mach = machine(Deterministic(), X, y; predict=yhat)
return!(mach, composite, verbosity)

(predict=yhat,)
end

MLJBase.load_path(::Type{<:SimpleDeterministicCompositeModel}) =
Expand Down
11 changes: 5 additions & 6 deletions test/strategies/grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,8 @@ end
tuned = machine(tuned_model, X, y)

fit!(tuned, verbosity=0)
r = MLJBase.report(tuned)
@test :model in collect(keys(r.best_report))
rep = MLJBase.report(tuned)
@test :best_report in keys(rep)
fp = fitted_params(tuned)
@test :model in collect(keys(fp.best_fitted_params))
b = fp.best_model
Expand Down Expand Up @@ -181,11 +180,11 @@ end
@test e_training != report(tuned).best_history_entry.measurement[1]

# test plotting part of report:
@test r.plotting.parameter_names ==
@test rep.plotting.parameter_names ==
["transformer.features", "model.lambda"]
@test r.plotting.parameter_scales == [:none, :log10]
@test r.plotting.measurements == measurements
@test size(r.plotting.parameter_values) == (40, 2)
@test rep.plotting.parameter_scales == [:none, :log10]
@test rep.plotting.measurements == measurements
@test size(rep.plotting.parameter_values) == (40, 2)

end

Expand Down

0 comments on commit 6a15fb5

Please sign in to comment.