1- str (model_metadata) = " $(model_metadata. name) from $(model_metadata. package_name) "
2-
31"""
4- attempt(f, message="" )
2+ attempt(f, message; throw=false )
53
64Return `(f(), "✓") if `f()` executes without throwing an
75exception. Otherwise, return `(ex, "×"), where `ex` is the exception
8- thrown.
6+ caught. Only truly throw the exception if `throw=true`.
97
108If `message` is not empty, then it is logged to `Info`, together with
119the second return value ("✓" or "×").
1210
11+
1312"""
14- function attempt (f, message= " " )
13+ function attempt (f, message; throw = false )
1514 ret = try
1615 (f (), " ✓" )
1716 catch ex
17+ throw && Base. throw (ex)
1818 (ex, " ×" )
1919 end
2020 isempty (message) || @info message* last (ret)
@@ -30,7 +30,7 @@ finalize(message, verbosity) = verbosity < 2 ? "" : message
3030# is updated to 0.16. And delete the two methods immediately
3131# following. What's required will already be in MLJModels 0.15.10, but
3232# the current implementation avoids an explicit MLJModels dependency
33- # for MLJTest .
33+ # for MLJTestIntegration .
3434load_path (model_type) = MLJ. load_path (model_type)
3535function load_path (proxy:: NamedTuple )
3636 handle = (name= proxy. name, pkg= proxy. package_name)
3939
4040root (load_path) = split (load_path, ' .' ) |> first
4141
42- function model_type (proxy, mod; verbosity= 1 )
42+ function model_type (proxy, mod; throw = false , verbosity= 1 )
4343 # check interface package really is in current environment:
44- message = " ` [:model_type]` Loading model type "
45- model_type, outcome = attempt (finalize (message, verbosity)) do
46- load_path = MLJTest . load_path (proxy) # MLJ.load_path(proxy) *****
44+ message = " [:model_type] Loading model type "
45+ model_type, outcome = attempt (finalize (message, verbosity); throw ) do
46+ load_path = MLJTestIntegration . load_path (proxy) # MLJ.load_path(proxy) *****
4747 load_path_ex = load_path |> Meta. parse
4848 api_pkg_ex = root (load_path) |> Symbol
4949 import_ex = :(import $ api_pkg_ex)
@@ -61,39 +61,39 @@ function model_type(proxy, mod; verbosity=1)
6161 # above, `model_type`, was triggered because of API package is
6262 # missing from in environment.
6363 api_pkg = try
64- load_path = MLJTest . load_path (proxy) # MLJ.load_path(proxy) *****
64+ load_path = MLJTestIntegration . load_path (proxy) # MLJ.load_path(proxy) *****
6565 api_pkg = root (load_path)
6666 catch
6767 nothing
6868 end
6969 if ! isnothing (api_pkg) &&
7070 api_pkg != " unknown" &&
7171 contains (model_type. msg, " $api_pkg not found in" )
72- throw (model_type)
72+ Base . throw (model_type)
7373 end
7474 end
7575
7676 return model_type, outcome
7777end
7878
79- function model_instance (model_type; verbosity= 1 )
80- message = " ` [:model_instance]` Instantiating default model "
81- attempt (finalize (message, verbosity)) do
79+ function model_instance (model_type; throw = false , verbosity= 1 )
80+ message = " [:model_instance] Instantiating default model "
81+ attempt (finalize (message, verbosity); throw ) do
8282 model_type ()
8383 end
8484end
8585
86- function fitted_machine (model, data... ; verbosity= 1 )
87- message = " ` [:fitted_machine]` Fitting machine "
88- attempt (finalize (message, verbosity)) do
86+ function fitted_machine (model, data... ; throw = false , verbosity= 1 )
87+ message = " [:fitted_machine] Fitting machine "
88+ attempt (finalize (message, verbosity); throw ) do
8989 mach = machine (model, data... )
9090 fit! (mach, verbosity= - 1 )
9191 end
9292end
9393
94- function operations (fitted_machine, data... ; verbosity= 1 )
95- message = " ` [:operations]` Calling `predict`, `transform` and/or `inverse_transform` "
96- attempt (finalize (message, verbosity)) do
94+ function operations (fitted_machine, data... ; throw = false , verbosity= 1 )
95+ message = " [:operations] Calling `predict`, `transform` and/or `inverse_transform` "
96+ attempt (finalize (message, verbosity); throw ) do
9797 operations = String[]
9898 methods = MLJ. implemented_methods (fitted_machine. model)
9999 if :predict in methods
@@ -112,30 +112,30 @@ function operations(fitted_machine, data...; verbosity=1)
112112 end
113113end
114114
115- function threshold_prediction (model, data... ; verbosity= 1 )
116- message = " ` [:threshold_predictor]` Calling fit!/predict for threshold predictor " *
115+ function threshold_prediction (model, data... ; throw = false , verbosity= 1 )
116+ message = " [:threshold_predictor] Calling fit!/predict for threshold predictor " *
117117 " test) "
118- attempt (finalize (message, verbosity)) do
118+ attempt (finalize (message, verbosity); throw ) do
119119 tmodel = BinaryThresholdPredictor (model)
120120 mach = machine (tmodel, data... )
121121 fit! (mach, verbosity= 0 )
122122 predict (mach, first (data))
123123 end
124124end
125125
126- function evaluation (measure, model, data... ; verbosity= 1 )
127- message = " ` [:evaluation]` Evaluating performance "
128- attempt (finalize (message, verbosity)) do
126+ function evaluation (measure, model, data... ; throw = false , verbosity= 1 )
127+ message = " [:evaluation] Evaluating performance "
128+ attempt (finalize (message, verbosity); throw ) do
129129 evaluate (model, data... ;
130130 measure= measure,
131131 resampling= Holdout (),
132132 verbosity= 0 )
133133 end
134134end
135135
136- function tuned_pipe_evaluation (measure, model, data... ; verbosity= 1 )
137- message = " ` [:tuned_pipe_evaluation]` Evaluating perfomance in a tuned pipeline "
138- attempt (finalize (message, verbosity)) do
136+ function tuned_pipe_evaluation (measure, model, data... ; throw = false , verbosity= 1 )
137+ message = " [:tuned_pipe_evaluation] Evaluating perfomance in a tuned pipeline "
138+ attempt (finalize (message, verbosity); throw ) do
139139 pipe = identity |> model
140140 tuned_pipe = TunedModel (models= [pipe,],
141141 measure= measure)
@@ -145,8 +145,8 @@ function tuned_pipe_evaluation(measure, model, data...; verbosity=1)
145145 end
146146end
147147
148- function ensemble_prediction (model, data... ; verbosity= 1 )
149- attempt (finalize (" ` [:ensemble_prediction]` Ensembling " , verbosity)) do
148+ function ensemble_prediction (model, data... ; throw = false , verbosity= 1 )
149+ attempt (finalize (" [:ensemble_prediction] Ensembling " , verbosity); throw ) do
150150 imodel = EnsembleModel (model= model,
151151 n= 2 )
152152 mach = machine (imodel, data... )
@@ -155,9 +155,9 @@ function ensemble_prediction(model, data...; verbosity=1)
155155 end
156156end
157157
158- function iteration_prediction (measure, model, data... ; verbosity= 1 )
159- message = " ` [:iteration_prediction]` Iterating with controls "
160- attempt (finalize (message, verbosity)) do
158+ function iteration_prediction (measure, model, data... ; throw = false , verbosity= 1 )
159+ message = " [:iteration_prediction] Iterating with controls "
160+ attempt (finalize (message, verbosity); throw ) do
161161 imodel = IteratedModel (model= model,
162162 measure= measure,
163163 controls= [Step (1 ),
0 commit comments