Once the name of a model, and the package providing that model, have been identified (see Model Search) one can either import the model type interactively with
@iload, as shown under Installation, or use
@load as shown below. The
@load macro works from within a module, a package or a function, provided the relevant package providing the MLJ interface has been added to your package environment. It will attempt to load the model type into the global namespace of the module in which
@load is invoked (
Main if invoked at the REPL).
In general, the code providing core functionality for the model (living in a packge you should consult for documentation) may be different from the package providing the MLJ interface. Since the core package is a dependency of the interface package, only the interface package needs to be added to your environment.
For instance, suppose you have activated a Julia package environment
my_env that you wish to use for your MLJ project; for example you have run:
using Pkg Pkg.activate("my_env", shared=true)
And, furthermore, suppose you want to use
DecisionTreeClassifier, provided by the DecisionTree.jl package. Then, to determine which package provides the MLJ interface you call
julia> load_path("DecisionTreeClassifier", pkg="DecisionTree") "MLJDecisionTreeInterface.DecisionTreeClassifier"
In this case we see that the package required is MLJDecisionTreeInterface.jl. If this package is not in
Pkg.status() to check) you add it by running
So long as
my_env is the active environment, this action need never be repeated (unless you run
Pkg.rm("MLJDecisionTreeInterface")). You are now ready to instantiate a decision tree classifier:
julia> Tree = @load DecisionTree pkg=DecisionTree julia> tree = Tree()
which is equivalent to
julia> import MLJDecisionTreeInterface.DecisionTreeClassifier julia> Tree = MLJDecisionTreeInterface.DecisionTreeClassifier julia> tree = Tree()
Tip. The specification
pkg=... above can be dropped for the many models that are provided by only a single package.
Return the load path for model type with name
model, specifying the package name
pkg to resolve name conflicts if necessary.
Return the load path of a
model instance or type. Usually requires necessary model code to have been separately loaded. Supply a string as above if code is not loaded.
@load ModelName pkg=nothing verbosity=0 add=false
Import the model type the model named in the first argument into the calling module, specfying
pkg in the case of an ambiguous name (to packages providing a model type with the same name). Returns the model type.
Warning In older versions of MLJ/MLJModels,
@load returned an instance instead.
To automatically add required interface packages to the current environment, specify
add=true. For interactive loading, use
Tree = @load DecisionTreeRegressor tree = Tree() tree2 = Tree(min_samples_split=6) SVM = @load SVC pkg=LIBSVM svm = SVM()
Interactive alternative to @load. Provides user with an optioin to install (add) the required interface package to the current environment, and to choose the relevant model-providing package in ambiguous cases. See