Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions examples/sacramento.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pins

from dotenv import load_dotenv
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import OneHotEncoder
from sklearn.pipeline import Pipeline
from vetiver.data import sacramento
from vetiver import VetiverModel, vetiver_pin_write

load_dotenv()

x = sacramento.drop(columns="price")
y = sacramento["price"]

ohe = OneHotEncoder().fit(x)
lm = LinearRegression().fit(ohe.transform(x), y)
pipeline = Pipeline([("ohe", ohe), ("linear_model", lm)])
v = VetiverModel(pipeline, "isabel.zimmerman/sacramento", x)
board = pins.board_connect(allow_pickle_read=True)
vetiver_pin_write(board=board, model=v)
6 changes: 0 additions & 6 deletions tox.ini

This file was deleted.

15 changes: 9 additions & 6 deletions vetiver/templates/model_card.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ display(Markdown(f"""
#| include: false
import pins

raw = "https://colorado.rstudio.com/rsc/"
paths = {"v": "sacramento/"}
raw = "https://pub.palm.ptd.posit.it/public"
paths = {"v": "vetiver-model-card/"}
board = pins.board_urls(raw, paths, allow_pickle_read=True)
```

Expand Down Expand Up @@ -51,13 +51,15 @@ display(Markdown(f"""
- A {model_desc} using {num_features} feature{'s'[:num_features^1]}.
"""))
```

- More details about how model was developed and what it is predicting
- More details on feature engineering and/or data preprocessing for model

```{python}
#| echo: false
version = v_meta.version
time_created = datetime.datetime
.strptime(v_meta.created, '%Y%m%dT%H%M%SZ')
time_created = datetime.datetime\
.strptime(v_meta.created, '%Y%m%dT%H%M%SZ')\
.strftime('%Y-%m-%d %H:%M:%S')

display(Markdown(f"""
Expand Down Expand Up @@ -91,7 +93,7 @@ display(Markdown(f"""
- The training dataset for this model has the "prototype" or signature:
```{python}
#| echo: false
v.prototype.construct().schema().get("properties")
v.prototype.model_json_schema()
```

- The evaluation dataset used in this model card is ...
Expand All @@ -105,6 +107,7 @@ v.prototype.construct().schema().get("properties")
## consider using a package like Pandas Profiling for automated EDA

```

## Overall model performance

```{python}
Expand Down Expand Up @@ -134,7 +137,7 @@ dmp
## Visualize model performance

```{python}
performance = px.scatter(sacramento, x="price", y = "preds", facet_row="type", trendline="ols")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing trendline to avoid forcing a statsmodels install, which is not a required package in vetiver

performance = px.scatter(sacramento, x="price", y = "preds", facet_row="type")
performance.update_yaxes(matches=None)
performance.show()
```
Expand Down
15 changes: 10 additions & 5 deletions vetiver/templates/monitoring_dashboard.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ from sklearn import metrics
from vetiver import VetiverModel, compute_metrics, plot_metrics
from sklearn.metrics import recall_score, accuracy_score

raw = "https://colorado.rstudio.com/rsc"
raw = "https://pub.palm.ptd.posit.it/public"
paths = {"chicago-model-python": "chicago-model-python/"}
board = pins.board_url(raw, paths, allow_pickle_read=True)
v = VetiverModel.from_pin(board, "chicago-model-python")
Expand All @@ -35,8 +35,8 @@ days_old = datetime.today() - datetime.strptime(v_meta.created, "%Y%m%dT%H%M%SZ"
## add any code you need to import new data and make predictions

# import new data to track performance over time
raw = "https://colorado.rstudio.com/rsc"
paths = {"new-data": "inspections-new-data/"}
raw = "https://pub.palm.ptd.posit.it/public"
paths = {"new-data": "inspections-monitor/"}
board = pins.board_url(raw, paths, allow_pickle_read=True)
inspections_new = board.pin_read("new-data")

Expand Down Expand Up @@ -73,7 +73,7 @@ Model details
- This model has the prototype:

```
`{python} v.prototype.construct().schema().get("properties")`
`{python} v.prototype.model_json_schema()`
```

- The model was created by ...
Expand Down Expand Up @@ -125,8 +125,13 @@ Write your own code to make visualizations or tables with the new validation dat
## Column

```{python}
# For your own model, you can use
# the following code with your URL
# to display your model API's visual documentation

from IPython.display import IFrame
IFrame('https://colorado.posit.co/rsc/chicago-inspections-python', width=750, height=350)
url = "your-model-api-url"
IFrame(url, width=750, height=350)
```
---

Expand Down
15 changes: 10 additions & 5 deletions vetiver/tests/snapshots/monitoring_dashboard.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ from sklearn import metrics
from vetiver import VetiverModel, compute_metrics, plot_metrics
from sklearn.metrics import recall_score, accuracy_score

raw = "https://colorado.rstudio.com/rsc"
raw = "https://pub.palm.ptd.posit.it/public"
paths = {"chicago-model-python": "chicago-model-python/"}
board = pins.board_url(raw, paths, allow_pickle_read=True)
v = VetiverModel.from_pin(board, "chicago-model-python")
Expand All @@ -35,8 +35,8 @@ days_old = datetime.today() - datetime.strptime(v_meta.created, "%Y%m%dT%H%M%SZ"
## add any code you need to import new data and make predictions

# import new data to track performance over time
raw = "https://colorado.rstudio.com/rsc"
paths = {"new-data": "inspections-new-data/"}
raw = "https://pub.palm.ptd.posit.it/public"
paths = {"new-data": "inspections-monitor/"}
board = pins.board_url(raw, paths, allow_pickle_read=True)
inspections_new = board.pin_read("new-data")

Expand Down Expand Up @@ -73,7 +73,7 @@ Model details
- This model has the prototype:

```
`{python} v.prototype.construct().schema().get("properties")`
`{python} v.prototype.model_json_schema()`
```

- The model was created by ...
Expand Down Expand Up @@ -125,8 +125,13 @@ Write your own code to make visualizations or tables with the new validation dat
## Column

```{python}
# For your own model, you can use
# the following code with your URL
# to display your model API's visual documentation

from IPython.display import IFrame
IFrame('https://colorado.posit.co/rsc/chicago-inspections-python', width=750, height=350)
url = "your-model-api-url"
IFrame(url, width=750, height=350)
```
---

Expand Down
Loading