How to load Python model in Plumber API?

Currently, I have an API that is deployed to Rstudio Connect. It uses a python imblearn Balanced Random Forest Classifier model, and the model is saved as a pkl file in the repo. So, the API is deployed with the pkl file as part of the bundle, and reads it in every time a new prediction is needed.

Now, I am trying to set up a re-training process that will re-train the model weekly on new data. Typically, I use pins to pin my ML models to Rstudio Connect (API will pull the pinned ML model to make new predictions), and then a Rmd file that will re-train and pin an updated model. This, of course, is to avoid having to re-deploy the API with the new model, and rather just modify the pin instead.

However, my issue is that I cannot replicate this process for a python based model. I am not able to pin a python model and use pin_get() within the API to read it in. Currently, I am stuck with having to re-train the model manually, committing the new model pkl file to the repo, and re-deploying the API.

I also have access to Microsoft SharePoint, where I can save a pkl file and pull it into Rstudio Workbench. However, I am not able to programmatically access SharePoint from the API once it's deployed to the Rstudio Connect Server.

Has anyone also run into this problem? Or have any suggestions to avoid this manual process?

Thank you!

I use an update endpoint on my plumber router.

The update endpoint basically pulls the model from a cloud bucket and reload the in memory object used by the prediction endpoint.

So after retraining is done, I save the model to the bucket and call the update endpoint.

1 Like