Intro to MLOps with vetiver
Data that you use while building a model for training/testing
New data that you predict on after your model deployed
👩🏼🔧 My model returns predictions quickly, doesn’t use too much memory or processing power, and doesn’t have outages.
Metrics
👩🏽🔬 My model returns predictions that are close to the true values for the predicted quantity.
Metrics
DATA drift
CONCEPT drift
Activity
Using our data, what could be an example of data drift? Concept drift?
05:00
Typically it is most useful to compare to your model development data1
Activity
Create a plot or table comparing the development vs. monitoring distributions of a model input/feature.
How might you make this comparison if you didn’t have all the model development data available when monitoring?
What summary statistics might you record during model development, to prepare for monitoring?
07:00
from vetiver import vetiver_endpoint, predict, compute_metrics, plot_metrics
from sklearn.metrics import root_mean_squared_error, r2_score, mean_absolute_error
from datetime import timedelta
import numpy as np
url = "https://pub.demo.posit.team/public/seattle-housing-python/predict"
endpoint = vetiver_endpoint(url)
housing_new["pred"] = predict(endpoint = url,
data = housing_new[["bedrooms", "bathrooms", "sqft_living", "yr_built"]])
housing_new["price"] = np.log10(housing_new["price"])
td = timedelta(weeks = 2)
metric_set = [root_mean_squared_error, r2_score, mean_absolute_error]
m = compute_metrics(
data = housing_new,
date_var = "date",
period = td,
metric_set = metric_set,
truth = "price",
estimate = "pred")
metrics_plot = plot_metrics(m).update_yaxes(matches = None)
library(vetiver)
library(tidymodels)
url <- "https://pub.demo.posit.team/public/seattle-housing-rstats/predict"
endpoint <- vetiver_endpoint(url)
augment(endpoint, new_data = housing_new) |>
mutate(price = log10(price)) |>
vetiver_compute_metrics(
date,
"week",
price,
.pred,
metric_set = metric_set(rmse, rsq, mae)
) |>
vetiver_plot_metrics()
Activity
Use the functions for metrics monitoring from vetiver to create a monitoring visualization.
Choose a different set of metrics or time aggregation.
Note that there are functions for using pins as a way to version and update monitoring results too!
05:00
Deployment of an ML model may alter the training data
Activity
What is a possible feedback loop for the Seattle housing data?
Do you think your example would be harmful or helpful? To whom?
05:00
Activity
Let’s say that the most important organizational outcome for a Seattle realtor is how accurate a pricing model is in terms of percentage on prices in USD rather than an absolute value. (Think about being 20% wrong vs. $20,000 wrong.)
We can measure this with the mean absolute percentage error.
Compute this quantity with the monitoring data, and aggregate by week/month, number of bedrooms/bathrooms, or waterfront status.
For extra credit, make a visualization showing your results.
07:00
Activity
Create a Quarto report or R Markdown dashboard for model monitoring.
Publish your document to Connect.
15:00
We made it! 🎉
Activity
What is one thing you learned that surprised you?
What is one thing you learned that you plan to use?
05:00
Documentation at https://vetiver.posit.co/
Isabel’s talk from rstudio::conf() 2022 on Demystifying MLOps
End-to-end demos from Posit Solution Engineering in R and Python
Are you on the right track with your MLOps system? Use the rubric in “The ML Test Score: A Rubric for ML Production Readiness and Technical Debt Reduction” by Breck et al (2017)
Want to learn about how MLOps is being practiced? Read one of our favorite 😍 recent papers, “Operationalizing Machine Learning: An Interview Study” by Shankar et al (2022)
Follow Posit and/or us on your preferred social media for updates!
Your feedback is crucial! Data from the survey informs curriculum and format decisions for future conf workshops and we really appreciate you taking the time to provide it.