Use a Custom Model¶
First, we'll initialize a client with our server credentials and store it in the variable dai
.
In [1]:
Copied!
import driverlessai
dai = driverlessai.Client(address='http://localhost:12345', username='py', password='py')
import driverlessai
dai = driverlessai.Client(address='http://localhost:12345', username='py', password='py')
Here we grab a custom recipe from our recipe repo (https://github.com/h2oai/driverlessai-recipes) and upload it to the Driverless AI server.
In [18]:
Copied!
dai.recipes.create('https://github.com/h2oai/driverlessai-recipes/raw/master/models/algorithms/catboost.py')
dai.recipes.create('https://github.com/h2oai/driverlessai-recipes/raw/master/models/algorithms/catboost.py')
Complete 100%
It's also possible to use the same dai.recipes.create()
function to upload recipes that we have written locally.
In [19]:
Copied!
dai.recipes.create('knearestneighbour.py')
dai.recipes.create('knearestneighbour.py')
Complete 100%
We can create a list of custom model recipe objects.
In [20]:
Copied!
custom_models = [m for m in dai.recipes.models.list() if m.is_custom]
display(custom_models)
custom_models = [m for m in dai.recipes.models.list() if m.is_custom]
display(custom_models)
[<class 'driverlessai.recipes.ModelRecipe'> CatBoost Model, <class 'driverlessai.recipes.ModelRecipe'> KNearestNeighbour Model, <class 'driverlessai.recipes.ModelRecipe'> LinearSVM Model]
For demonstration purposes, we'll grab the first dataset available on the server.
Then, we'll use it to get an experiment preview.
Note that CatBoost
and KNearestNeighbour
are now listed as 'models to train'.
In [21]:
Copied!
ds = dai.datasets.list()[0]
dai.experiments.preview(
train_dataset=ds,
target_column=ds.columns[-1],
task='classification',
models=custom_models
)
ds = dai.datasets.list()[0]
dai.experiments.preview(
train_dataset=ds,
target_column=ds.columns[-1],
task='classification',
models=custom_models
)
ACCURACY [7/10]: - Training data size: *150 rows, 5 cols* - Feature evolution: *[CatBoost, KNearestNeighbour]*, *3-fold CV**, 2 reps* - Final pipeline: *Ensemble (3 models), 3-fold CV* TIME [2/10]: - Feature evolution: *8 individuals*, up to *42 iterations* - Early stopping: After *5* iterations of no improvement INTERPRETABILITY [8/10]: - Feature pre-pruning strategy: Permutation Importance FS - Monotonicity constraints: enabled - Feature engineering search space: [CVCatNumEncode, CVTargetEncode, CatOriginal, Cat, Frequent, Interactions, NumCatTE, Original, Text] [CatBoost, KNearestNeighbour] models to train: - Model and feature tuning: *192* - Feature evolution: *288* - Final pipeline: *3* Estimated runtime: *minutes* Auto-click Finish/Abort if not done in: *1 day*/*7 days*