pin_metrics

pin_metrics(
    board,
    df_metrics: pd.DataFrame,
    metrics_pin_name: str,
    pin_type: str | None = None,
    index_name: str = 'index',
    overwrite: bool = False,
)

Update an existing pin storing model metrics over time

Parameters

board :

Pins board

df_metrics : pd.DataFrame

Dataframe of metrics over time, such as created by vetiver_compute_metrics()

metrics_pin_name : str

Pin name for where the metrics are stored

index_name : str = 'index'

The column in df_metrics containing the aggregated dates or datetimes. Note that this defaults to a column named “index”.

overwrite : bool = False

If True, overwrite any metrics for dates that exist both in the existing pin and new metrics with the new values. If False, error when the new metrics contain overlapping dates with the existing pin.

Examples

import pins
import vetiver
df = pd.DataFrame(
{'index': {0: pd.Timestamp('2021-01-01 00:00:00'),
           1: pd.Timestamp('2021-01-01 00:00:00'),
           2: pd.Timestamp('2021-01-02 00:00:00'),
           3: pd.Timestamp('2021-01-02 00:00:00')},
 'n': {0: 1, 1: 1, 2: 1, 3: 1},
 'metric': {0: 'mean_squared_error',
            1: 'mean_absolute_error',
            2: 'mean_squared_error',
            3: 'mean_absolute_error'},
 'estimate': {0: 4.0, 1: 2.0, 2: 1.0, 3: 1.0}}
)
board = pins.board_temp()
board.pin_write(df, "metrics", type = "csv")

df = pd.DataFrame(
{'index': {0: pd.Timestamp('2021-01-02 00:00:00'),
           1: pd.Timestamp('2021-01-02 00:00:00'),
           2: pd.Timestamp('2021-01-03 00:00:00'),
           3: pd.Timestamp('2021-01-03 00:00:00')},
 'n': {0: 1, 1: 1, 2: 1, 3: 1},
 'metric': {0: 'mean_squared_error',
            1: 'mean_absolute_error',
            2: 'mean_squared_error',
            3: 'mean_absolute_error'},
 'estimate': {0: 4.0, 1: 6.0, 2: 2.0, 3: 1.0}}
)
vetiver.pin_metrics(
   board=board,
   df_metrics=df2,
   metrics_pin_name="metrics",
   index_name="index",
   overwrite=True)