eval_nowcast
eval_nowcast_model(model, dataset, time_interval='month', window_size=12)
¶
Evaluates a time series model using a rolling mean absolute error metric.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
time_series
|
A predictor object (river.time_series) that implements the forecast and learn_one methods. |
required |
dataset |
object
|
A dataset object that contains the time series data. |
required |
time_interval |
str
|
The name of the attribute that contains the date information in the dataset. |
'month'
|
window_size |
int
|
The number of observations to use for calculating the rolling metric. |
12
|
Returns:
Type | Description |
---|---|
Tuple[List, Rolling, List, List]
|
Tuple[List, utils.Rolling, List, List]: A tuple of four lists: - dates: The dates corresponding to each observation in the dataset. - metric: A rolling metric object that contains the mean absolute error values. - y_trues: The true values of the target variable in the dataset. - y_preds: The predicted values of the target variable by the model. |
Examples:
>>> from river import compose
from river import linear_model
from river import preprocessing, datasets, utils, metrics
import matplotlib.pyplot as plt
from spotriver.utils.features import get_ordinal_date
from spotriver.evaluation.eval_nowcast import eval_nowcast_model, plot_nowcast_model
model = compose.Pipeline(
('ordinal_date', compose.FuncTransformer(get_ordinal_date)),
('scale', preprocessing.StandardScaler()),
('lin_reg', linear_model.LinearRegression())
)
dataset = datasets.AirlinePassengers()
dates, metric, y_trues, y_preds = eval_nowcast_model(model, dataset=dataset)
plot_nowcast_model(dates, metric, y_trues, y_preds)
Source code in spotriver/evaluation/eval_nowcast.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
plot_nowcast_model(dates, metric, y_trues, y_preds, range=None)
¶
Plots the true values and the predictions of a nowcast model along with a rolling metric.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dates |
List[str]
|
A list of strings that contains the dates corresponding to each observation. |
required |
metric |
Rolling
|
A rolling metric object that contains the mean absolute error values. |
required |
y_trues |
List[float]
|
A list of floats that contains the true values of the target variable. |
required |
y_preds |
List[float]
|
A list of floats that contains the predicted values of the target variable. |
required |
range |
List[int]
|
A list of 2 int that specify the subset. |
None
|
Returns:
Type | Description |
---|---|
None
|
None. Displays a matplotlib figure with two lines and a title. |
Source code in spotriver/evaluation/eval_nowcast.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|