|
| 1 | +--- |
| 2 | +title: "Model Card: your model title" |
| 3 | +date: '`python date.today()`' |
| 4 | +output: |
| 5 | + html_document |
| 6 | +params: |
| 7 | + board: !python pins.board_rsconnect() |
| 8 | + name: isabel.zimmerman/sacramento_rf |
| 9 | + version: NULL |
| 10 | +--- |
| 11 | + |
| 12 | +```{python setup, include=FALSE} |
| 13 | +from datetime import date |
| 14 | +from sklearn import metrics |
| 15 | +import vetiver |
| 16 | +import pins |
| 17 | +
|
| 18 | +# library(yardstick) |
| 19 | +# knitr::opts_chunk$set(echo = FALSE) |
| 20 | +v = vetiver.VetiverModel.from_pin(pins.board_rsconnect(server_url = "https://colorado.rstudio.com/rsc/"), "isabel.zimmerman/cars_mpg") |
| 21 | +``` |
| 22 | + |
| 23 | +A [model card](https://doi.org/10.1145/3287560.3287596) provides brief, transparent, responsible reporting for a trained machine learning model. |
| 24 | + |
| 25 | +## Model details |
| 26 | + |
| 27 | +- Developed by PERSON AND/OR TEAM |
| 28 | +- `python print(f"{v.description} using {v.ptype} features")` |
| 29 | +- More details about how model was developed and what it is predicting |
| 30 | +- More details on feature engineering and/or data preprocessing for model |
| 31 | +- Version `python v.metadata.version` of this model was published at `r v_meta.created` |
| 32 | +- Citation and/or license details for the model |
| 33 | +- If you have questions about this model, please contact PERSON@ORG.ORG |
| 34 | + |
| 35 | +## Intended use |
| 36 | + |
| 37 | +- The primary intended uses of this model are ... |
| 38 | +- The primary intended users of this model are ... |
| 39 | +- Some use cases are out of scope for this model, such as ... |
| 40 | + |
| 41 | +## Important aspects/factors |
| 42 | + |
| 43 | +- Aspects or factors (demographic, environmental, technical) that are relevant to the context of this model are ... |
| 44 | +- In evaluating this model, we examined aspects such as ... |
| 45 | + |
| 46 | +## Metrics |
| 47 | + |
| 48 | +- The metrics used to evaluate this model are ... |
| 49 | +- These metrics are computed via ... |
| 50 | +- We chose these metrics because ... |
| 51 | + |
| 52 | +## Training data & evaluation data |
| 53 | + |
| 54 | +- The training dataset for this model was ... |
| 55 | +- The training dataset for this model has the "prototype" or signature: |
| 56 | + |
| 57 | +```{python} |
| 58 | +v.ptype |
| 59 | +``` |
| 60 | + |
| 61 | +- The evaluation dataset used in this model card is ... |
| 62 | +- We chose this evaluation data because ... |
| 63 | + |
| 64 | +```{python} |
| 65 | +## EVALUATION DATA: |
| 66 | +from vetiver.data import mtcars |
| 67 | +## consider using a package like skimr or DataExplorer for automated |
| 68 | +## presentation of evaluation data characteristics |
| 69 | +``` |
| 70 | + |
| 71 | + |
| 72 | +## Quantitative analyses {.tabset} |
| 73 | + |
| 74 | +```{python} |
| 75 | +## compute predictions for your evaluation data |
| 76 | +## `handler_startup` is designed to get the R process ready to make predictions |
| 77 | +#suppressPackageStartupMessages(handler_startup(v)) |
| 78 | +new_data["preds"] = v.model.predict(mtcars.drop(columns="mpg")) |
| 79 | +``` |
| 80 | + |
| 81 | + |
| 82 | +### Overall model performance |
| 83 | + |
| 84 | +```{python} |
| 85 | +
|
| 86 | +metric_set = [metrics.mean_absolute_error, metrics.mean_squared_error] |
| 87 | +
|
| 88 | +``` |
| 89 | + |
| 90 | +### Disaggregated model performance |
| 91 | + |
| 92 | +```{python} |
| 93 | +
|
| 94 | +preds %>% |
| 95 | + group_by(type) %>% |
| 96 | + metrics(price, .pred) |
| 97 | +``` |
| 98 | + |
| 99 | +### Visualize model performance |
| 100 | + |
| 101 | +```{python, fig.height=3} |
| 102 | +preds %>% |
| 103 | + ggplot(aes(price, .pred, color = type)) + |
| 104 | + geom_abline(slope = 1, lty = 2, color = "gray60", size = 1.2) + |
| 105 | + geom_point(alpha = 0.5, show.legend = FALSE) + |
| 106 | + facet_wrap(vars(type)) |
| 107 | +``` |
| 108 | + |
| 109 | +### Make a custom plot |
| 110 | + |
| 111 | +```{r} |
| 112 | +preds %>% |
| 113 | + mutate(.resid = price - .pred) %>% |
| 114 | + ggplot(aes(longitude, latitude, color = .resid)) + |
| 115 | + geom_point(alpha = 0.8) + |
| 116 | + scale_color_gradient2() + |
| 117 | + coord_fixed() |
| 118 | +``` |
| 119 | + |
| 120 | + |
| 121 | +## Ethical considerations |
| 122 | + |
| 123 | +- We considered ... |
| 124 | + |
| 125 | +## Caveats & recommendations |
| 126 | + |
| 127 | +- This model does ... |
| 128 | +- This model does not ... |
| 129 | +- We recommend ... |
0 commit comments