You can run this notebook in a live session Binder or view it on Github.

Automate Machine Learning with TPOT

This example shows how TPOT can be used with Dask.

TPOT is an automated machine learning library. It evaluates many scikit-learn pipelines and hyperparameter combinations to find a model that works well for your data. Evaluating all these computations is computationally expensive, but ammenable to parallelism. TPOT can use Dask to distribute these computations on a cluster of machines.

This notebook can be run interactively on the dask examples binder. The following video shows a larger version of this notebook on a cluster.

In [1]:
from IPython.display import HTML

HTML('<div style="position:relative;height:0;padding-bottom:56.25%"><iframe src="" width="640" height="360" frameborder="0" allow="autoplay; encrypted-media" style="position:absolute;width:100%;height:100%;left:0" allowfullscreen></iframe></div>')
In [ ]:
!pip install tpot
In [ ]:
from tpot import TPOTClassifier
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split

Setup Dask

We first start a Dask client in order to get access to the Dask dashboard, which will provide progress and performance metrics.

You can view the dashboard by clicking on the dashboard link after you run the cell.

In [ ]:
from dask.distributed import Client
client = Client(n_workers=4, threads_per_worker=1)

Create Data

We’ll use the digits dataset. To ensure the example runs quickly, we’ll make the training dataset relatively small.

In [ ]:
digits = load_digits()

X_train, X_test, y_train, y_test = train_test_split(,,

These are just small, in-memory NumPy arrays. This example is not applicable to larger-than-memory Dask arrays.

Using Dask

TPOT follows the scikit-learn API; we specify a TPOTClassifier with a few hyperparameters, and then fit it on some data. By default, TPOT trains on your single machine. To ensure your cluster is used, specify the use_dask keyword.

In [ ]:
# scale up: Increase the TPOT parameters like population_size, generations
tp = TPOTClassifier(
In [ ]:, y_train)

Learn More

See the Dask-ML and TPOT documenation for more information on using Dask and TPOT.