1
- str (model_metadata) = " $(model_metadata. name) from $(model_metadata. package_name) "
2
-
3
1
"""
4
- attempt(f, message="" )
2
+ attempt(f, message; throw=false )
5
3
6
4
Return `(f(), "✓") if `f()` executes without throwing an
7
5
exception. Otherwise, return `(ex, "×"), where `ex` is the exception
8
- thrown.
6
+ caught. Only truly throw the exception if `throw=true`.
9
7
10
8
If `message` is not empty, then it is logged to `Info`, together with
11
9
the second return value ("✓" or "×").
12
10
11
+
13
12
"""
14
- function attempt (f, message= " " )
13
+ function attempt (f, message; throw = false )
15
14
ret = try
16
15
(f (), " ✓" )
17
16
catch ex
17
+ throw && Base. throw (ex)
18
18
(ex, " ×" )
19
19
end
20
20
isempty (message) || @info message* last (ret)
@@ -30,7 +30,7 @@ finalize(message, verbosity) = verbosity < 2 ? "" : message
30
30
# is updated to 0.16. And delete the two methods immediately
31
31
# following. What's required will already be in MLJModels 0.15.10, but
32
32
# the current implementation avoids an explicit MLJModels dependency
33
- # for MLJTest .
33
+ # for MLJTestIntegration .
34
34
load_path (model_type) = MLJ. load_path (model_type)
35
35
function load_path (proxy:: NamedTuple )
36
36
handle = (name= proxy. name, pkg= proxy. package_name)
39
39
40
40
root (load_path) = split (load_path, ' .' ) |> first
41
41
42
- function model_type (proxy, mod; verbosity= 1 )
42
+ function model_type (proxy, mod; throw = false , verbosity= 1 )
43
43
# 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) *****
47
47
load_path_ex = load_path |> Meta. parse
48
48
api_pkg_ex = root (load_path) |> Symbol
49
49
import_ex = :(import $ api_pkg_ex)
@@ -61,39 +61,39 @@ function model_type(proxy, mod; verbosity=1)
61
61
# above, `model_type`, was triggered because of API package is
62
62
# missing from in environment.
63
63
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) *****
65
65
api_pkg = root (load_path)
66
66
catch
67
67
nothing
68
68
end
69
69
if ! isnothing (api_pkg) &&
70
70
api_pkg != " unknown" &&
71
71
contains (model_type. msg, " $api_pkg not found in" )
72
- throw (model_type)
72
+ Base . throw (model_type)
73
73
end
74
74
end
75
75
76
76
return model_type, outcome
77
77
end
78
78
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
82
82
model_type ()
83
83
end
84
84
end
85
85
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
89
89
mach = machine (model, data... )
90
90
fit! (mach, verbosity= - 1 )
91
91
end
92
92
end
93
93
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
97
97
operations = String[]
98
98
methods = MLJ. implemented_methods (fitted_machine. model)
99
99
if :predict in methods
@@ -112,30 +112,30 @@ function operations(fitted_machine, data...; verbosity=1)
112
112
end
113
113
end
114
114
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 " *
117
117
" test) "
118
- attempt (finalize (message, verbosity)) do
118
+ attempt (finalize (message, verbosity); throw ) do
119
119
tmodel = BinaryThresholdPredictor (model)
120
120
mach = machine (tmodel, data... )
121
121
fit! (mach, verbosity= 0 )
122
122
predict (mach, first (data))
123
123
end
124
124
end
125
125
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
129
129
evaluate (model, data... ;
130
130
measure= measure,
131
131
resampling= Holdout (),
132
132
verbosity= 0 )
133
133
end
134
134
end
135
135
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
139
139
pipe = identity |> model
140
140
tuned_pipe = TunedModel (models= [pipe,],
141
141
measure= measure)
@@ -145,8 +145,8 @@ function tuned_pipe_evaluation(measure, model, data...; verbosity=1)
145
145
end
146
146
end
147
147
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
150
150
imodel = EnsembleModel (model= model,
151
151
n= 2 )
152
152
mach = machine (imodel, data... )
@@ -155,9 +155,9 @@ function ensemble_prediction(model, data...; verbosity=1)
155
155
end
156
156
end
157
157
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
161
161
imodel = IteratedModel (model= model,
162
162
measure= measure,
163
163
controls= [Step (1 ),
0 commit comments