Now that MLow has saved the logs of each experiment, we can go back through
and examine the results. From your Databricks notebook, select the “Runs” icon in
the upper right-hand corner to view and compare the results of each of our runs.
Not surprisingly, as we increase our “stretch factor,” our distance metric decreases.
Intuitively, this makes sense: As we give the algorithm more exibility to warp the
time indices forward or backward, it will nd a closer t for the data. In essence,
we’ve traded some bias for variance.
Logging models in MLow
MLow has the ability to not only log experiment parameters, metrics and artifacts
(like plots or CSV les), but also to log machine learning models. An MLow model
is simply a folder that is structured to conform to a consistent API, ensuring
compatibility with other MLow tools and features. This interoperability is very
powerful, allowing any Python model to be rapidly deployed to many different
types of production environments.
MLow comes preloaded with a number of common model “avors” for many
of the most popular machine learning libraries, including scikit-learn, Spark MLlib,
PyTorch, TensorFlow and others. These model avors make it trivial to log and reload
models after they are initially constructed, as demonstrated in this blog post. For
example, when using MLow with scikit-learn, logging a model is as easy as running
the following code from within an experiment:
mlow.sklearn.log_model(model=sk_model, artifact_path=”sk_model_path”)
MLow also offers a “Python function” avor, which allows you to save any
model from a third-party library (such as XGBoost or spaCy), or even a simple
Python function itself, as an MLow model. Models created using the Python
function avor live within the same ecosystem and are able to interact with other
MLow tools through the Inference API. Although it’s impossible to plan for every
use case, the Python function model avor was designed to be as universal and
exible as possible. It allows for custom processing and logic evaluation, which
can come in handy for ETL applications. Even as more “ofcial” model avors
come online, the generic Python function avor will still serve as an important
“catchall,” providing a bridge between Python code of any kind and MLow’s
robust tracking toolkit.
Logging a model using the Python function avor is a straightforward process.
Any model or function can be saved as a model, with one requirement: It
must take in a pandas DataFrame as input, and return a DataFrame or NumPy
array. Once that requirement is met, saving your function as an MLow model
involves dening a Python class that inherits from PythonModel, and overriding the
.predict() method with your custom function, as described here.
16EBOOK: THE BIG BOOK OF MACHINE LEARNING USE CASES