Skip to content

Commit c6b33de

Browse files
authored
maint: update templates to render out of the box (#229)
* update templates to ptd palm * remove API url iframe- will not work on palm
1 parent 949e349 commit c6b33de

File tree

5 files changed

+49
-22
lines changed

5 files changed

+49
-22
lines changed

examples/sacramento.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import pins
2+
3+
from dotenv import load_dotenv
4+
from sklearn.linear_model import LinearRegression
5+
from sklearn.preprocessing import OneHotEncoder
6+
from sklearn.pipeline import Pipeline
7+
from vetiver.data import sacramento
8+
from vetiver import VetiverModel, vetiver_pin_write
9+
10+
load_dotenv()
11+
12+
x = sacramento.drop(columns="price")
13+
y = sacramento["price"]
14+
15+
ohe = OneHotEncoder().fit(x)
16+
lm = LinearRegression().fit(ohe.transform(x), y)
17+
pipeline = Pipeline([("ohe", ohe), ("linear_model", lm)])
18+
v = VetiverModel(pipeline, "isabel.zimmerman/sacramento", x)
19+
board = pins.board_connect(allow_pickle_read=True)
20+
vetiver_pin_write(board=board, model=v)

tox.ini

Lines changed: 0 additions & 6 deletions
This file was deleted.

vetiver/templates/model_card.qmd

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ display(Markdown(f"""
1717
#| include: false
1818
import pins
1919
20-
raw = "https://colorado.rstudio.com/rsc/"
21-
paths = {"v": "sacramento/"}
20+
raw = "https://pub.palm.ptd.posit.it/public"
21+
paths = {"v": "vetiver-model-card/"}
2222
board = pins.board_urls(raw, paths, allow_pickle_read=True)
2323
```
2424

@@ -51,13 +51,15 @@ display(Markdown(f"""
5151
- A {model_desc} using {num_features} feature{'s'[:num_features^1]}.
5252
"""))
5353
```
54+
5455
- More details about how model was developed and what it is predicting
5556
- More details on feature engineering and/or data preprocessing for model
57+
5658
```{python}
5759
#| echo: false
5860
version = v_meta.version
59-
time_created = datetime.datetime
60-
.strptime(v_meta.created, '%Y%m%dT%H%M%SZ')
61+
time_created = datetime.datetime\
62+
.strptime(v_meta.created, '%Y%m%dT%H%M%SZ')\
6163
.strftime('%Y-%m-%d %H:%M:%S')
6264
6365
display(Markdown(f"""
@@ -91,7 +93,7 @@ display(Markdown(f"""
9193
- The training dataset for this model has the "prototype" or signature:
9294
```{python}
9395
#| echo: false
94-
v.prototype.construct().schema().get("properties")
96+
v.prototype.model_json_schema()
9597
```
9698

9799
- The evaluation dataset used in this model card is ...
@@ -105,6 +107,7 @@ v.prototype.construct().schema().get("properties")
105107
## consider using a package like Pandas Profiling for automated EDA
106108
107109
```
110+
108111
## Overall model performance
109112

110113
```{python}
@@ -134,7 +137,7 @@ dmp
134137
## Visualize model performance
135138

136139
```{python}
137-
performance = px.scatter(sacramento, x="price", y = "preds", facet_row="type", trendline="ols")
140+
performance = px.scatter(sacramento, x="price", y = "preds", facet_row="type")
138141
performance.update_yaxes(matches=None)
139142
performance.show()
140143
```

vetiver/templates/monitoring_dashboard.qmd

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ from sklearn import metrics
2222
from vetiver import VetiverModel, compute_metrics, plot_metrics
2323
from sklearn.metrics import recall_score, accuracy_score
2424
25-
raw = "https://colorado.rstudio.com/rsc"
25+
raw = "https://pub.palm.ptd.posit.it/public"
2626
paths = {"chicago-model-python": "chicago-model-python/"}
2727
board = pins.board_url(raw, paths, allow_pickle_read=True)
2828
v = VetiverModel.from_pin(board, "chicago-model-python")
@@ -35,8 +35,8 @@ days_old = datetime.today() - datetime.strptime(v_meta.created, "%Y%m%dT%H%M%SZ"
3535
## add any code you need to import new data and make predictions
3636
3737
# import new data to track performance over time
38-
raw = "https://colorado.rstudio.com/rsc"
39-
paths = {"new-data": "inspections-new-data/"}
38+
raw = "https://pub.palm.ptd.posit.it/public"
39+
paths = {"new-data": "inspections-monitor/"}
4040
board = pins.board_url(raw, paths, allow_pickle_read=True)
4141
inspections_new = board.pin_read("new-data")
4242
@@ -73,7 +73,7 @@ Model details
7373
- This model has the prototype:
7474

7575
```
76-
`{python} v.prototype.construct().schema().get("properties")`
76+
`{python} v.prototype.model_json_schema()`
7777
```
7878

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

127127
```{python}
128+
# For your own model, you can use
129+
# the following code with your URL
130+
# to display your model API's visual documentation
131+
128132
from IPython.display import IFrame
129-
IFrame('https://colorado.posit.co/rsc/chicago-inspections-python', width=750, height=350)
133+
url = "your-model-api-url"
134+
IFrame(url, width=750, height=350)
130135
```
131136
---
132137

vetiver/tests/snapshots/monitoring_dashboard.qmd

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ from sklearn import metrics
2222
from vetiver import VetiverModel, compute_metrics, plot_metrics
2323
from sklearn.metrics import recall_score, accuracy_score
2424
25-
raw = "https://colorado.rstudio.com/rsc"
25+
raw = "https://pub.palm.ptd.posit.it/public"
2626
paths = {"chicago-model-python": "chicago-model-python/"}
2727
board = pins.board_url(raw, paths, allow_pickle_read=True)
2828
v = VetiverModel.from_pin(board, "chicago-model-python")
@@ -35,8 +35,8 @@ days_old = datetime.today() - datetime.strptime(v_meta.created, "%Y%m%dT%H%M%SZ"
3535
## add any code you need to import new data and make predictions
3636
3737
# import new data to track performance over time
38-
raw = "https://colorado.rstudio.com/rsc"
39-
paths = {"new-data": "inspections-new-data/"}
38+
raw = "https://pub.palm.ptd.posit.it/public"
39+
paths = {"new-data": "inspections-monitor/"}
4040
board = pins.board_url(raw, paths, allow_pickle_read=True)
4141
inspections_new = board.pin_read("new-data")
4242
@@ -73,7 +73,7 @@ Model details
7373
- This model has the prototype:
7474

7575
```
76-
`{python} v.prototype.construct().schema().get("properties")`
76+
`{python} v.prototype.model_json_schema()`
7777
```
7878

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

127127
```{python}
128+
# For your own model, you can use
129+
# the following code with your URL
130+
# to display your model API's visual documentation
131+
128132
from IPython.display import IFrame
129-
IFrame('https://colorado.posit.co/rsc/chicago-inspections-python', width=750, height=350)
133+
url = "your-model-api-url"
134+
IFrame(url, width=750, height=350)
130135
```
131136
---
132137

0 commit comments

Comments
 (0)