|
1 | | -module TestEnsembles |
2 | | - |
3 | | -using Test |
4 | | -using Random |
5 | | -using StableRNGs |
6 | | -using MLJEnsembles |
7 | | -using MLJBase |
8 | | -using ..Models |
9 | | -using CategoricalArrays |
10 | | -import Distributions |
11 | | -using StatisticalMeasures |
12 | | - |
13 | 1 | ## HELPER FUNCTIONS |
14 | 2 |
|
15 | 3 | @test MLJEnsembles._reducer([1, 2], [3, ]) == [1, 2, 3] |
@@ -187,10 +175,10 @@ predict(ensemble_model, fitresult, MLJEnsembles.selectrows(X, test)) |
187 | 175 |
|
188 | 176 | @testset "further test of sample weights" begin |
189 | 177 | ## Note: This testset also indirectly tests for compatibility with the data-front end |
190 | | - # implemented by `KNNClassifier` as calls to `fit`/`predict` on an `Ensemble` model |
| 178 | + # implemented by `KNNClassifier` as calls to `fit`/`predict` on an `Ensemble` model |
191 | 179 | # with `atom=KNNClassifier` would error if the ensemble implementation doesn't handle |
192 | 180 | # data front-end conversions properly. |
193 | | - |
| 181 | + |
194 | 182 | rng = StableRNG(123) |
195 | 183 | N = 20 |
196 | 184 | X = (x = rand(rng, 3N), ); |
@@ -224,18 +212,18 @@ predict(ensemble_model, fitresult, MLJEnsembles.selectrows(X, test)) |
224 | 212 | end |
225 | 213 |
|
226 | 214 |
|
227 | | -## MACHINE TEST |
| 215 | +## MACHINE TEST |
228 | 216 | ## (INCLUDES TEST OF UPDATE. |
229 | | -## ALSO INCLUDES COMPATIBILITY TESTS FOR ENSEMBLES WITH ATOM MODELS HAVING A |
| 217 | +## ALSO INCLUDES COMPATIBILITY TESTS FOR ENSEMBLES WITH ATOM MODELS HAVING A |
230 | 218 | ## DIFFERENT DATA FRONT-END SEE #16) |
231 | 219 |
|
232 | | -@testset "machine tests" begin |
| 220 | +@testset_accelerated "machine tests" acceleration begin |
233 | 221 | N =100 |
234 | 222 | X = (x1=rand(N), x2=rand(N), x3=rand(N)) |
235 | 223 | y = 2X.x1 - X.x2 + 0.05*rand(N) |
236 | 224 |
|
237 | 225 | atom = KNNRegressor(K=7) |
238 | | - ensemble_model = EnsembleModel(model=atom) |
| 226 | + ensemble_model = EnsembleModel(; model=atom, acceleration) |
239 | 227 | ensemble = machine(ensemble_model, X, y) |
240 | 228 | train, test = partition(eachindex(y), 0.7) |
241 | 229 | fit!(ensemble, rows=train, verbosity=0) |
@@ -264,15 +252,13 @@ end |
264 | 252 | atom; |
265 | 253 | bagging_fraction=0.6, |
266 | 254 | rng=123, |
267 | | - out_of_bag_measure = [log_loss, brier_score] |
| 255 | + out_of_bag_measure = [log_loss, brier_score], |
| 256 | + acceleration, |
268 | 257 | ) |
269 | 258 | ensemble = machine(ensemble_model, X_, y_) |
270 | 259 | fit!(ensemble) |
271 | 260 | @test length(ensemble.fitresult.ensemble) == ensemble_model.n |
272 | 261 |
|
273 | 262 | end |
274 | 263 |
|
275 | | - |
276 | | -end |
277 | | - |
278 | 264 | true |
0 commit comments