diff --git a/Project.toml b/Project.toml index c51915d..917f72f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MLJTuning" uuid = "03970b2e-30c4-11ea-3135-d1576263f10f" authors = ["Anthony D. Blaom "] -version = "0.7.1" +version = "0.7.2" [deps] ComputationalResources = "ed09eef8-17a6-5b46-8889-db040fac31e3" diff --git a/README.md b/README.md index 983354f..0855f00 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ Hyperparameter optimization for [MLJ](https://github.com/alan-turing-institute/MLJ.jl) machine learning models. +See [**Tuning Models ยท MLJ**](https://alan-turing-institute.github.io/MLJ.jl/dev/tuning_models) for usage examples. + [![Build Status](https://github.com/JuliaAI/MLJTuning.jl/workflows/CI/badge.svg)](https://github.com/JuliaAI/MLJTuning.jl/actions) [![codecov.io](http://codecov.io/github/JuliaAI/MLJTuning.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaAI/MLJTuning.jl?branch=master) @@ -32,7 +34,7 @@ hyperparameter optimization tasks from there. MLJTuning is the place for developers to integrate hyperparameter optimization algorithms (here called *tuning strategies*) into MLJ, either by adding code to [/src/strategies](/src/strategies), or by -importing MLJTuning into a third-pary package and implementing +importing MLJTuning into a third-party package and implementing MLJTuning's [tuning strategy interface](#how-do-i-implement-a-new-tuning-strategy). MLJTuning is a component of the [MLJ diff --git a/src/tuned_models.jl b/src/tuned_models.jl index 853c74d..29713c2 100644 --- a/src/tuned_models.jl +++ b/src/tuned_models.jl @@ -19,6 +19,10 @@ const ERR_BOTH_DISALLOWED = ArgumentError( "You cannot specify both `model` and `models`. ") const ERR_MODEL_TYPE = ArgumentError( "Only `Deterministic` and `Probabilistic` model types supported.") +const ERR_UNINSTANTIATED_MODEL = AssertionError( + "Type encountered where model instance expected. (Tuning evaluates "* + "models by mutating clones of the provided instance, as specified "* + "by `range`.) ") const INFO_MODEL_IGNORED = "`model` being ignored. Using `model=first(range)`. " const ERR_TOO_MANY_ARGUMENTS = @@ -260,11 +264,11 @@ function TunedModel(args...; model=nothing, # user can specify model as argument instead of kwarg: length(args) < 2 || throw(ERR_TOO_MANY_ARGUMENTS) - if length(args) === 1 + if length(args) == 1 arg = first(args) model === nothing || @warn warn_double_spec(arg, model) - model =arg + model = arg end # either `models` is specified and `tuning` is set to `Explicit`, @@ -309,7 +313,10 @@ function TunedModel(args...; model=nothing, else throw(ERR_MODEL_TYPE) end + elseif model isa Type + throw(ERR_UNINSTANTIATED_MODEL) else + # Model is probably an instantiated model. M = typeof(model) end diff --git a/test/runtests.jl b/test/runtests.jl index 9877ccc..75d0d61 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,11 +9,7 @@ using StableRNGs # Display Number of processes and if necessary number # of Threads @info "nworkers: $(nworkers())" -@static if VERSION >= v"1.3.0-DEV.573" - @info "nthreads: $(Threads.nthreads())" -else - @info "Running julia $(VERSION). Multithreading tests excluded. " -end +@info "nthreads: $(Threads.nthreads())" include("test_utilities.jl") diff --git a/test/tuned_models.jl b/test/tuned_models.jl index c512d9a..bfec7a4 100644 --- a/test/tuned_models.jl +++ b/test/tuned_models.jl @@ -17,10 +17,10 @@ N = 30 x1 = rand(N); x2 = rand(N); x3 = rand(N); -X = (x1=x1, x2=x2, x3=x3); +X = (; x1, x2, x3); y = 2*x1 .+ 5*x2 .- 3*x3 .+ 0.4*rand(N); -m(K) = KNNRegressor(K=K) +m(K) = KNNRegressor(; K) r = [m(K) for K in 13:-1:2] # TODO: replace the above with the line below and post an issue on @@ -66,6 +66,8 @@ r = [m(K) for K in 13:-1:2] tm = @test_logs TunedModel(model=first(r), range=r, measure=rms) @test tm.tuning isa RandomSearch @test input_scitype(tm) == Table(Continuous) + + @test_throws MLJTuning.ERR_UNINSTANTIATED_MODEL TunedModel(; model=KNNRegressor, range=r) end results = [(evaluate(model, X, y,