Sign inGet started
← Back to all posts

Deploy ML models to Snowflake with Deepnote & Modelbit

By Harry Glaser

Updated on July 7, 2022

Learn how to build and train a machine learning model in Deepnote and deploy it to Snowflake using Modelbit.

Illustrative image for blog post

Modelbit offers an easy way to deploy machine learning models from notebooks directly into Snowflake. So when you need to collaborate on a model and deploy it to Snowflake, using Deepnote and Modelbit together is the perfect combination.

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'll work with an 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 data set into a pandas DataFrame.


Now that we’ve got this data set, let’s build a model. In this example, we're going to try to predict a player's position. 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 and 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 data set 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.

Harry Glaser

CEO @ Modelbit

Follow Harry on LinkedIn


Illustrative image for blog post

Beyond AI chatbots: how we tripled engagement with Deepnote AI

By Gabor Szalai

Updated on April 3, 2024

That’s it, time to try Deepnote

Get started – it’s free
Book a demo



  • Integrations
  • Pricing
  • Documentation
  • Changelog
  • Security




  • Privacy
  • Terms

© Deepnote