Simple ML Model Inference using Scikit learn

My machine learning students asked me to make a demo for them showing how to load their models on to Anvil and perform inferences. Their models are trained on their own computers and then pickled (via Pickle or Joblib).

Here is a quick demo I put together using a model I made for the Iris dataset (yes I know, boring):
https://anvil.works/build#clone:SFPPBC2QAH3AEKDF=6Q27MK3YTSZX5SXCOPIWERUW

Dependencies:

Lessons Learned:

  • Don’t forget about your virtual environment! I ran into an issue with differing versions of scikit-learn on my machine and the server. Some class names were changed in version 0.22 and my pickled model wouldn’t load with the servers 0.20.3 version.
  • KISS (Keep it simple stupid) is really the idea here. Pickled models are quite small, and loading it to a data table as a media object is really easy and more reliable than saving it in the filesystem.

Edit: Dependencies are now cloned as well :slight_smile:

6 Likes

One thing to note here. The Slider custom component only accepted an int. So I went into the code for the custom component and changed line 58 from

    self._level = int(value)

to:

    self._level = float(value)

and it all worked nicely.

1 Like

I accidentally broke the clone link above by deleting a dependency. Here is the proper one:

https://anvil.works/build#clone:SFPPBC2QAH3AEKDF=6Q27MK3YTSZX5SXCOPIWERUW

1 Like