How to deploy your ML model from Deepnote to Snowflake using Modelbit

Harry Glaser, Co-Founder & CEO
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Deepnote offers a collaborative Python notebook experience. Modelbit offers an easy way to deploy ML models from notebooks directly into Snowflake. So when you need to collaborate on a model and then deploy it to Snowflake, using Deepnote and Modelbit together are the perfect combination.

In this post, we’ll walk you through building and training a model in Deepnote, and then deploying it to Snowflake using Modelbit.

To start, make sure the "modelbit" package is in your Deepnote project’s "requirements.txt". Then, go ahead and log into Modelbit like so:

From there, you can call "mb.datasets()" to get a list of your datasets:

In this example, we’re going to work with that "nba games" dataset. It provides stat lines for every NBA player in every NBA game – fun for us Golden State Warriors fans on the west coast! Let’s go ahead and pull that dataset into a Pandas DataFrame.

Now that we’ve got this dataset, let’s build a model. In this example, we’re going to try to predict what position a player plays! Let’s use a RandomForestClassifier, courtesy of SciKit-Learn:

As you can see, we’re using three features to predict the player’s position: the number of three-point shots they attempt (FG3A), the number of rebounds they get (REB), and the number of shots they block (BLK).

We do some feature engineering in the next few lines, dropping unused columns as well as dropping rows with NaNs in any of our feature or target columns. Finally, we use SciKit-Learn’s built-in train/test split functionality to split our dataset into training data and testing data.

Finally, we train a RandomForestClassifier, which we call position_classifier. Let’s see how it did!

Our model has an accuracy score of about 0.6. Not bad for a first attempt!

Let’s go ahead and deploy this model to Snowflake. To do that, we’re going to build a quick function that null-checks our inputs and builds a DataFrame out of them. Once that’s done, we can feed those inputs to our model’s predict function and return its prediction!

Testing our function locally, we see that a player that attempts 15 three-pointers, while only getting one rebound and no blocks, is likely a Guard. That checks out. 😉

Now, to deploy the model, we call Modelbit’s "deploy" function, passing it our "predictPosition" function!

All done! If we click that link, we’re taken to our Modelbit account, where we can see our model in action, including sample Snowflake code, production Python environment, logs and more:

If we go ahead and copy that sample Snowflake code into our Snowflake worksheet, we can call our model directly from Snowflake!

From here, you can call that model every time a new row is inserted, every time you build a rollup table, or in batch on all the rows!

Deploy Custom ML Models to Production with Modelbit

Join other world class machine learning teams deploying customized machine learning models to REST Endpoints.
Get Started for Free