compute_metrics(
data: pd.DataFrame,
date_var: str,
period: timedelta,
metric_set: list,
truth: str,
estimate: str,
**kw,
)
Compute metrics for given time period
Parameters
data : DataFrame
-
Pandas dataframe
date_var : str
-
Column in data
containing dates
period : timedelta
-
Defining period to group by
metric_set : list
-
List of metrics to compute, that have the parameters y_true
and y_pred
truth : str
-
Column name for true results
estimate : str
-
Column name for predicted results
Examples
import pandas as pd
from vetiver import compute_metrics
from datetime import timedelta
from sklearn.metrics import mean_squared_error, mean_absolute_error
df = pd.DataFrame(
{
"index": ["2021-01-01", "2021-01-02", "2021-01-03"],
"truth": [200, 201, 199],
"pred": [198, 200, 199],
}
)
td = timedelta(days = 1)
metric_set = [mean_squared_error, mean_absolute_error]
metrics = compute_metrics(df, "index", td, metric_set, "truth", "pred")
metrics
0 |
2021-01-01 |
1 |
mean_squared_error |
4.0 |
1 |
2021-01-01 |
1 |
mean_absolute_error |
2.0 |
2 |
2021-01-02 |
1 |
mean_squared_error |
1.0 |
3 |
2021-01-02 |
1 |
mean_absolute_error |
1.0 |