|
| 1 | +--- |
| 2 | +title: "Monitoring dashboard" |
| 3 | +format: |
| 4 | + dashboard: |
| 5 | + orientation: columns |
| 6 | +logo: https://github.com/rstudio/vetiver-python/blob/main/docs/figures/logo.png?raw=true |
| 7 | +output: asis |
| 8 | +jupyter: python3 |
| 9 | +--- |
| 10 | + |
| 11 | +```{python} |
| 12 | +#| include: false |
| 13 | +#| tags: [parameters] |
| 14 | +
|
| 15 | +# import model and metadata |
| 16 | +import pins |
| 17 | +from IPython.display import display, Markdown, IFrame |
| 18 | +from datetime import datetime, timedelta |
| 19 | +import pandas as pd |
| 20 | +import plotly.express as px |
| 21 | +from sklearn import metrics |
| 22 | +from vetiver import VetiverModel, compute_metrics, plot_metrics |
| 23 | +from sklearn.metrics import recall_score, accuracy_score |
| 24 | +
|
| 25 | +raw = "https://colorado.rstudio.com/rsc" |
| 26 | +paths = {"chicago-model-python": "chicago-model-python/"} |
| 27 | +board = pins.board_url(raw, paths, allow_pickle_read=True) |
| 28 | +v = VetiverModel.from_pin(board, "chicago-model-python") |
| 29 | +v_meta = board.pin_meta("chicago-model-python") |
| 30 | +days_old = datetime.today() - datetime.strptime(v_meta.created, "%Y%m%dT%H%M%SZ") |
| 31 | +``` |
| 32 | + |
| 33 | +```{python} |
| 34 | +## the next few lines are an example model, here is a place to |
| 35 | +## add any code you need to import new data and make predictions |
| 36 | +
|
| 37 | +# import new data to track performance over time |
| 38 | +raw = "https://colorado.rstudio.com/rsc" |
| 39 | +paths = {"new-data": "inspections-new-data/"} |
| 40 | +board = pins.board_url(raw, paths, allow_pickle_read=True) |
| 41 | +inspections_new = board.pin_read("new-data") |
| 42 | +
|
| 43 | +# make predictions |
| 44 | +inspections_new["preds"] = v.model.predict( |
| 45 | + inspections_new.drop(columns=["results", "aka_name", "inspection_date"]) |
| 46 | +) |
| 47 | +
|
| 48 | +# map results |
| 49 | +inspections_new["preds"] = inspections_new["preds"].map({"PASS": 0, "FAIL": 1}) |
| 50 | +inspections_new["results"] = inspections_new["results"].map({"PASS": 0, "FAIL": 1}) |
| 51 | +``` |
| 52 | + |
| 53 | +# Model info |
| 54 | + |
| 55 | +## Column |
| 56 | +### Row {height="33%"} |
| 57 | +::: {.valuebox} |
| 58 | +`{python} v.description` |
| 59 | + |
| 60 | +`{python} v.model_name` |
| 61 | +::: |
| 62 | + |
| 63 | +::: {.valuebox} |
| 64 | +Model age |
| 65 | + |
| 66 | +`{python} days_old.days` days old |
| 67 | +::: |
| 68 | + |
| 69 | +### Row |
| 70 | + |
| 71 | +Model details |
| 72 | + |
| 73 | +- This model has the prototype: |
| 74 | + |
| 75 | +``` |
| 76 | +`{python} v.prototype.construct().schema().get("properties")` |
| 77 | +``` |
| 78 | + |
| 79 | +- The model was created by ... |
| 80 | + |
| 81 | +# Model metrics |
| 82 | + |
| 83 | +## Column |
| 84 | +```{python} |
| 85 | +import itables |
| 86 | +
|
| 87 | +td = timedelta(weeks = 4) |
| 88 | +metric_set = [accuracy_score, recall_score] |
| 89 | +
|
| 90 | +metrics_df = compute_metrics( |
| 91 | + data = inspections_new, |
| 92 | + date_var = "inspection_date", |
| 93 | + period = td, |
| 94 | + metric_set = metric_set, |
| 95 | + truth = "results", |
| 96 | + estimate = "preds" |
| 97 | + ) |
| 98 | +itables.show(metrics_df) |
| 99 | +``` |
| 100 | + |
| 101 | +```{python} |
| 102 | +plot_metrics(metrics_df).show() |
| 103 | +``` |
| 104 | + |
| 105 | +## Column {.sidebar} |
| 106 | + |
| 107 | +This tab is used to see model performance over time. In this context, _performance_ is the statistical properties of the model, eg, accuracy and recall. |
| 108 | + |
| 109 | +You can add custom information and metrics here. |
| 110 | + |
| 111 | +# Explore validation data |
| 112 | + |
| 113 | +```{python} |
| 114 | +fig = px.histogram(inspections_new, x = "facility_type") |
| 115 | +fig.show() |
| 116 | +``` |
| 117 | + |
| 118 | +## Column {.sidebar} |
| 119 | + |
| 120 | +Write your own code to make visualizations or tables with the new validation data, and/or the new predictions. |
| 121 | + |
| 122 | + |
| 123 | +# API visual documentation |
| 124 | + |
| 125 | +## Column |
| 126 | + |
| 127 | +```{python} |
| 128 | +from IPython.display import IFrame |
| 129 | +IFrame('https://colorado.posit.co/rsc/chicago-inspections-python', width=750, height=350) |
| 130 | +``` |
| 131 | +--- |
| 132 | + |
| 133 | + |
| 134 | +## Column {.sidebar} |
| 135 | + |
| 136 | +Interact directly with your model via its visual documentation, and get `curl` examples. |
0 commit comments