Snowflake Model Registry
In this tutorial we will show how you can create a model in a notebook, save that model to the model registry and deploy/use that model via SQL.
Video
Video still in development
Requirement
- Snowflake account, you can use a free trial. We also assume no complex security needs.
Download
- Notebook (Link)
Setup
Lets start by adding some sample data and uploading our notebook.
If you don't have a database, schema or warehouse yet.
use role accountadmin;
-- Create a database to store our schemas.
create database if not exists raw;
-- Create the schema. The schema stores all our objectss.
create schema if not exists raw.science;
/*
Warehouses are synonymous with the idea of compute
resources in other systems. We will use this
warehouse to call our user defined function.
*/
create warehouse if not exists development
warehouse_size = xsmall
auto_suspend = 30
initially_suspended = true;
use database raw;
use schema science;
use warehouse development;
Sample data
First lets start by creating some sample data for our model to train from.
Upload and Setup Notebook
Lets upload our notebook we downloaded earlier. Start by navigating to notebooks and clicking import .ipynb file
.
Next we'll name it and select the location and that we want to run via a warehouse.
Our final step before running is to install the needed package snowflake-ml-python
to build and save our model. The package comes with sklearn
with it.
Run the notebook
To run the notebook we'll click run all
.
Once the model is run we can refresh our schema to see a model object has been added. We'll want to open the details to get our metrics we saved in the notebook.
We can click on the version we just created.
We can see the metadata our model and also the functions we will use in the next section to make predictions via SQL.
Use the model via SQL
Now that we have our model saved into our model registry, lets use the model via sql to make a prediction. Lets open a new worksheet.
We can also select specific versions if we have multiple or want to retrieve the latest model version..
Change default version
Updating the version can allow us to make sure downstream users are using the correct model.