Learners

Learner Interface

The core object used throughout all IAI packages is the learner (often abbreviated in code as lnr). This is the model object that holds all of the parameters that configure the behavior of the algorithm, as well as the fitted model.

There are many different types of learner, depending on the type of problem and the specific algorithm being used. Refer to the specific module documentation for information about the corresponding learner types that are available:

Creating Learners

You can make a learner by creating an instance of the learner type. For example, we can create an OptimalTreeClassifier by running:

lnr = IAI.OptimalTreeClassifier()
Unfitted OptimalTreeClassifier

Parameters

Learners have a number of parameters that can be changed to control the behavior of the algorithm. These can be set in the following ways (again with OptimalTreeClassifier as an example):

Warning

Learner objects have some fields that are used internally and should not be modified. Any field with a name ending in _ is for internal use and should not be set.

Common learner parameters

There are some parameters used by all IAI learners that can be used to control the behavior of the algorithm:

Regression learner parameters

The following parameters are used by all regression learners:

Prescription learner parameters

The following parameter is used by all prescription learners:

Fitting and Evaluating Learners

Once the learner is created and the parameters chosen, it can be fit using the training data using fit!:

using CSV
df = CSV.read("iris.csv")
X = df[:, 1:4]
y = df[:, 5]
lnr = IAI.OptimalTreeClassifier(max_depth=2, cp=0)
IAI.fit!(lnr, X, y)
Optimal Trees Visualization

We can make predictions on new feature data with predict:

IAI.predict(lnr, X)
150-element Array{String,1}:
 "setosa"
 "setosa"
 "setosa"
 "setosa"
 "setosa"
 "setosa"
 "setosa"
 "setosa"
 "setosa"
 "setosa"
 ⋮
 "virginica"
 "virginica"
 "virginica"
 "virginica"
 "virginica"
 "virginica"
 "virginica"
 "virginica"
 "virginica"

We can evaluate the quality of the learner on new data with score:

IAI.score(lnr, X, y)
0.96

There are a number of additional functions that can be used depending on the task type:

Utilities

You can save a learner to JSON format with write_json:

IAI.write_json("learner.json", lnr)

To read a saved learner back into Julia, use read_json:

lnr = IAI.read_json("learner.json")
Optimal Trees Visualization

The following functions to make it easier to work with learners and their parameters in a general manner: