how to plot fan chart using VAR? #6753
-
I tried to use VAR and plot the fan chart for one variable but got the following error. Can someone kindly advise how to fix the error?
The following code works, s 8000 o this seems to be a problem of multiindexing?
|
Beta Was this translation helpful? Give feedback.
Answered by
SultanOrazbayev
Jul 12, 2024
Replies: 1 comment
-
Hello, Sakai! The issue here is at how pandas treats levels of a DataFrame. Here's the way to solve it: import numpy as np
import pandas as pd
from sktime.forecasting.var import VAR
from sktime.utils.plotting import plot_series
y_train = pd.DataFrame(np.random.rand(1000, 3), columns=["x1", "x2", "x3"])
forecaster = VAR(maxlags=1)
forecaster.fit(y_train)
y_pred = forecaster.predict(fh=range(1, 100))
coverage = 0.9
y_pred_ints1 = forecaster.predict_interval(coverage=coverage)
variable_to_plot = "x1"
pred_interval = y_pred_ints1[[variable_to_plot]].copy()
pred_interval.columns = pred_interval.columns.remove_unused_levels()
plot_series(y_train[[variable_to_plot]], y_pred[[variable_to_plot]], pred_interval=pred_interval) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sakaiando
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, Sakai!
The issue here is at how pandas treats levels of a DataFrame. Here's the way to solve it: