Versioning models with vetiver and pins
In Lesson 1, Dev's targets pipeline started producing a trained model that predicts which meal-kit customers will cancel. Good. But right now that model is just a variable sitting in his R session. Close the laptop and it is gone. Retrain it next week and the old one is quietly overwritten, with no record of which model actually made last month's predictions.
Code has git for exactly this problem. Models had nothing. This lesson gives them the same discipline: a place to register a model, keep every version, and retrieve any one of them on demand.
By the end of this lesson you will be able to:
- Explain why a model left as a workspace object is unsafe to ship
- Store a model on a board and read it back, in any session, with pins
- Keep and retrieve past versions of a model, and understand what vetiver adds on top
Prerequisites: you can fit a model end to end and read predict output, and you can write a function. The four boxes below are the model's whole life in production; this lesson is the second one.
A trained model is just a loose object
Let us rebuild Dev's model so we can see the problem for real. Each lesson runs in a fresh R session, so here is a small stand-in for his customer data (one row per customer: boxes ordered, weeks since the last order, spend per box, and whether they cancelled) and the model fit on it.
That model is a live object in memory, and nothing more. It predicts fine right now, but it has no home on disk, no name the rest of your team can ask for, and no record of when or how it was built.