@@ -11,6 +11,7 @@ def compute_metrics(
1111 metric_set : list ,
1212 truth : str ,
1313 estimate : str ,
14+ ** kw ,
1415) -> pd .DataFrame :
1516 """
1617 Compute metrics for given time period
@@ -32,6 +33,8 @@ def compute_metrics(
3233
3334 Example
3435 -------
36+ >>> from datetime import timedelta
37+ >>> import pandas as pd
3538 >>> from sklearn.metrics import mean_squared_error, mean_absolute_error
3639 >>> df = pd.DataFrame(
3740 ... {
@@ -62,7 +65,9 @@ def compute_metrics(
6265 "index" : i .index [0 ],
6366 "n" : len (i ),
6467 "metric" : m .__qualname__ ,
65- "estimate" : m (y_pred = i [truth ], y_true = i [estimate ]),
68+ # TODO: non-y_pred and y_true metrics
69+ # TODO: multioutput metrics
70+ "estimate" : m (y_pred = i [estimate ], y_true = i [truth ], ** kw ),
6671 }
6772 ]
6873
@@ -105,11 +110,50 @@ def pin_metrics(
105110 The column in df_metrics containing the aggregated dates or datetimes.
106111 Note that this defaults to a column named "index".
107112 overwrite: bool
108- If TRUE (the default), overwrite any metrics for
109- dates that exist both in the existing pin and
110- new metrics with the new values. If FALSE, error
111- when the new metrics contain overlapping dates with
113+ If True, overwrite any metrics for dates that exist both
114+ in the existing pin and new metrics with the new values.
115+ If False, error when the new metrics contain overlapping dates with
112116 the existing pin.
117+
118+ Example
119+ -------
120+ >>> import pins
121+ >>> import vetiver
122+ >>> df = pd.DataFrame(
123+ ... {'index': {0: pd.Timestamp('2021-01-01 00:00:00'),
124+ ... 1: pd.Timestamp('2021-01-01 00:00:00'),
125+ ... 2: pd.Timestamp('2021-01-02 00:00:00'),
126+ ... 3: pd.Timestamp('2021-01-02 00:00:00')},
127+ ... 'n': {0: 1, 1: 1, 2: 1, 3: 1},
128+ ... 'metric': {0: 'mean_squared_error',
129+ ... 1: 'mean_absolute_error',
130+ ... 2: 'mean_squared_error',
131+ ... 3: 'mean_absolute_error'},
132+ ... 'estimate': {0: 4.0, 1: 2.0, 2: 1.0, 3: 1.0}}
133+ ... )
134+ >>> board = pins.board_temp()
135+
136+ >>> board.pin_write(df, "metrics", type = "csv") # doctest: +SKIP
137+ >>> df = pd.DataFrame(
138+ ... {'index': {0: pd.Timestamp('2021-01-02 00:00:00'),
139+ ... 1: pd.Timestamp('2021-01-02 00:00:00'),
140+ ... 2: pd.Timestamp('2021-01-03 00:00:00'),
141+ ... 3: pd.Timestamp('2021-01-03 00:00:00')},
142+ ... 'n': {0: 1, 1: 1, 2: 1, 3: 1},
143+ ... 'metric': {0: 'mean_squared_error',
144+ ... 1: 'mean_absolute_error',
145+ ... 2: 'mean_squared_error',
146+ ... 3: 'mean_absolute_error'},
147+ ... 'estimate': {0: 4.0, 1: 6.0, 2: 2.0, 3: 1.0}}
148+ ... )
149+ >>> vetiver.pin_metrics( # doctest: +SKIP
150+ ... board=board,
151+ ... df_metrics=df2,
152+ ... metrics_pin_name="metrics",
153+ ... index_name="index",
154+ ... overwrite=True)
155+
156+
113157 """
114158
115159 old_metrics_raw = board .pin_read (metrics_pin_name )
@@ -170,6 +214,30 @@ def plot_metrics(
170214 Column in `df_metrics` containing metric name
171215 n: str
172216 Column in `df_metrics` containing number of observations
217+
218+ Example
219+ -------
220+ >>> import vetiver
221+ >>> import pandas as pd
222+ >>> df = pd.DataFrame(
223+ ... {'index': {0: pd.Timestamp('2021-01-01 00:00:00'),
224+ ... 1: pd.Timestamp('2021-01-01 00:00:00'),
225+ ... 2: pd.Timestamp('2021-01-02 00:00:00'),
226+ ... 3: pd.Timestamp('2021-01-02 00:00:00')},
227+ ... 'n': {0: 1, 1: 1, 2: 1, 3: 1},
228+ ... 'metric': {0: 'mean_squared_error',
229+ ... 1: 'mean_absolute_error',
230+ ... 2: 'mean_squared_error',
231+ ... 3: 'mean_absolute_error'},
232+ ... 'estimate': {0: 4.0, 1: 2.0, 2: 1.0, 3: 1.0}}
233+ ... )
234+ >>> plot = vetiver.plot_metrics(
235+ ... df_metrics = df,
236+ ... date = "index",
237+ ... estimate = "estimate",
238+ ... metric = "metric",
239+ ... n = "n")
240+ >>> plot.show() # doctest: +SKIP
173241 """
174242
175243 fig = px .line (
0 commit comments