plot_interval#
- plot_interval(ax, interval_df)[source]#
Plot prediction intervals on an existing matplotlib axes.
This function overlays prediction intervals on an existing plot to visualize forecast uncertainty.
- Parameters:
- axmatplotlib.axes.Axes
The axes to add the prediction intervals to.
- interval_dfpd.DataFrame
A multi-index DataFrame containing prediction intervals.
- Returns:
- axmatplotlib.axes.Axes
The matplotlib axes with the prediction intervals added.
Examples
>>> import pandas as pd >>> import numpy as np >>> from sktime.datasets import load_airline >>> from sktime.forecasting.naive import NaiveForecaster >>> from sktime.split import temporal_train_test_split >>> from sktime.forecasting.base import ForecastingHorizon >>> from sktime.utils.plotting import plot_series, plot_interval
>>> data = load_airline() >>> y_train, y_test = temporal_train_test_split(data, test_size=12)
>>> forecaster = NaiveForecaster(strategy="last") >>> _ = forecaster.fit(y_train)
>>> fh = ForecastingHorizon(y_test.index, is_relative=False) >>> interval_df = forecaster.predict_interval(fh=fh)
>>> y_train.index = y_train.index.to_timestamp() >>> y_test.index = y_test.index.to_timestamp() >>> interval_df.index = interval_df.index.to_timestamp()
>>> fig, ax = plot_series( ... y_train, y_test, labels=["Train", "Test"], ... pred_interval=interval_df, ... ) >>> plot_interval(ax, interval_df)
>>> ax.set_title('Predictions with Confidence Intervals') >>> ax.set_xlabel('Date') >>> ax.set_ylabel('Passengers')