plots¶
Functions
|
Plot per-segment metrics distribution. |
|
Plot targets and forecast for backtest pipeline. |
|
Plot targets and forecast for backtest pipeline using plotly. |
|
Plot of prediction for forecast pipeline. |
|
Plot of prediction and its components. |
|
Plot barplot with per-segment metrics. |
|
Plot residuals for predictions from backtest against some feature. |
|
Plot scatter plot with forecasted/actual values for segments. |
|
Plot Q-Q plots for segments. |
Classes
|
Enum for components plotting modes. |
|
Enum for types of plot in |
|
Enum for types of aggregation in a metric per-segment plot. |
- class MetricPlotType(value)[source]¶
Enum for types of plot in
metric_per_segment_distribution_plot()
.- hist¶
Histogram plot,
seaborn.histplot()
is used
- box¶
Boxplot,
seaborn.boxplot()
is used
- violin¶
Violin plot,
seaborn.violinplot()
is used
- class PerFoldAggregation(value)[source]¶
Enum for types of aggregation in a metric per-segment plot.
- metric_per_segment_distribution_plot(metrics_df: pandas.core.frame.DataFrame, metric_name: str, per_fold_aggregation_mode: Optional[str] = None, plot_type: Union[Literal['hist'], Literal['box'], Literal['violin']] = 'hist', seaborn_params: Optional[Dict[str, Any]] = None, figsize: Tuple[int, int] = (10, 5))[source]¶
Plot per-segment metrics distribution.
- Parameters
metrics_df (pandas.core.frame.DataFrame) – dataframe with metrics calculated on the backtest
metric_name (str) – name of the metric to visualize
per_fold_aggregation_mode (Optional[str]) –
If None, separate distributions for each fold will be drawn
If str, determines how to aggregate metrics over the folds if they aren’t already aggregated
(see
PerFoldAggregation
)plot_type (Union[Literal['hist'], typing.Literal['box'], typing.Literal['violin']]) – type of plot (see
MetricPlotType
)seaborn_params (Optional[Dict[str, Any]]) – dictionary with parameters for plotting
figsize (Tuple[int, int]) – size of the figure per subplot with one segment in inches
- Raises
ValueError: – if
metric_name
isn’t present inmetrics_df
NotImplementedError: – unknown
per_fold_aggregation_mode
is given
- plot_backtest(forecast_df: pandas.core.frame.DataFrame, ts: TSDataset, segments: Optional[List[str]] = None, columns_num: int = 2, history_len: Union[int, Literal['all']] = 0, figsize: Tuple[int, int] = (10, 5))[source]¶
Plot targets and forecast for backtest pipeline.
This function doesn’t support intersecting folds.
- Parameters
forecast_df (pandas.core.frame.DataFrame) – forecasted dataframe with timeseries data
ts (TSDataset) – dataframe of timeseries that was used for backtest
segments (Optional[List[str]]) – segments to plot
columns_num (int) – number of subplots columns
history_len (Union[int, Literal['all']]) – length of pre-backtest history to plot, if value is “all” then plot all the history
figsize (Tuple[int, int]) – size of the figure per subplot with one segment in inches
- Raises
ValueError: – if
history_len
is negativeValueError: – if folds are intersecting
- plot_backtest_interactive(forecast_df: pandas.core.frame.DataFrame, ts: TSDataset, segments: Optional[List[str]] = None, history_len: Union[int, Literal['all']] = 0, figsize: Tuple[int, int] = (900, 600)) plotly.graph_objs._figure.Figure [source]¶
Plot targets and forecast for backtest pipeline using plotly.
- Parameters
forecast_df (pandas.core.frame.DataFrame) – forecasted dataframe with timeseries data
ts (TSDataset) – dataframe of timeseries that was used for backtest
segments (Optional[List[str]]) – segments to plot
history_len (Union[int, Literal['all']]) – length of pre-backtest history to plot, if value is “all” then plot all the history
figsize (Tuple[int, int]) – size of the figure in pixels
- Returns
result of plotting
- Return type
go.Figure
- Raises
ValueError: – if
history_len
is negativeValueError: – if folds are intersecting
- plot_forecast(forecast_ts: Union[TSDataset, List[TSDataset], Dict[str, TSDataset]], test_ts: Optional[TSDataset] = None, train_ts: Optional[TSDataset] = None, segments: Optional[List[str]] = None, n_train_samples: Optional[int] = None, columns_num: int = 2, figsize: Tuple[int, int] = (10, 5), prediction_intervals: bool = False, quantiles: Optional[List[float]] = None)[source]¶
Plot of prediction for forecast pipeline.
- Parameters
forecast_ts (Union[TSDataset, List[TSDataset], Dict[str, TSDataset]]) –
there are several options:
Forecasted TSDataset with timeseries data, single-forecast mode
List of forecasted TSDatasets, multi-forecast mode
Dictionary with forecasted TSDatasets, multi-forecast mode
test_ts (Optional[TSDataset]) – TSDataset with timeseries data
train_ts (Optional[TSDataset]) – TSDataset with timeseries data
segments (Optional[List[str]]) – segments to plot; if not given plot all the segments from
forecast_df
n_train_samples (Optional[int]) – length of history of train to plot
columns_num (int) – number of graphics columns
figsize (Tuple[int, int]) – size of the figure per subplot with one segment in inches
prediction_intervals (bool) – if True prediction intervals will be drawn
quantiles (Optional[List[float]]) – List of quantiles to draw, if isn’t set then quantiles from a given dataset will be used. In multi-forecast mode, only quantiles present in each forecast will be used.
- Raises
ValueError: – if the format of
forecast_ts
is unknown
- plot_forecast_decomposition(forecast_ts: TSDataset, test_ts: Optional[TSDataset] = None, mode: Union[Literal['per-component'], Literal['joint']] = 'per-component', segments: Optional[List[str]] = None, columns_num: int = 1, figsize: Tuple[int, int] = (10, 5), show_grid: bool = False)[source]¶
Plot of prediction and its components.
- Parameters
forecast_ts (TSDataset) – forecasted TSDataset with timeseries data, single-forecast mode
test_ts (Optional[TSDataset]) – TSDataset with timeseries data
mode (Union[Literal['per-component'], typing.Literal['joint']]) –
Components plotting type
per-component
– plot each component in separate axesjoint
– plot all the components in the same axis
segments (Optional[List[str]]) – segments to plot; if not given plot all the segments
columns_num (int) – number of graphics columns; when mode=``per-component`` all plots will be in the single column
figsize (Tuple[int, int]) – size of the figure per subplot with one segment in inches
show_grid (bool) – whether to show grid for each chart
- Raises
ValueError: – if components aren’t present in
forecast_ts
NotImplementedError: – unknown
mode
is given
- plot_metric_per_segment(metrics_df: pandas.core.frame.DataFrame, metric_name: str, ascending: bool = False, per_fold_aggregation_mode: str = 'mean', top_k: Optional[int] = None, barplot_params: Optional[Dict[str, Any]] = None, figsize: Tuple[int, int] = (10, 5))[source]¶
Plot barplot with per-segment metrics.
- Parameters
metrics_df (pandas.core.frame.DataFrame) – dataframe with metrics calculated on the backtest
metric_name (str) – name of the metric to visualize
ascending (bool) –
If True, small values at the top;
If False, big values at the top.
per_fold_aggregation_mode (str) – how to aggregate metrics over the folds if they aren’t already aggregated (see
PerFoldAggregation
)top_k (Optional[int]) – number segments to show after ordering according to
ascending
barplot_params (Optional[Dict[str, Any]]) – dictionary with parameters for plotting,
seaborn.barplot()
is usedfigsize (Tuple[int, int]) – size of the figure per subplot with one segment in inches
- Raises
ValueError: – if
metric_name
isn’t present inmetrics_df
NotImplementedError: – unknown
per_fold_aggregation_mode
is given
- plot_residuals(forecast_df: pandas.core.frame.DataFrame, ts: TSDataset, feature: Union[str, Literal['timestamp']] = 'timestamp', transforms: Sequence[Transform] = (), segments: Optional[List[str]] = None, columns_num: int = 2, figsize: Tuple[int, int] = (10, 5))[source]¶
Plot residuals for predictions from backtest against some feature.
- Parameters
forecast_df (pandas.core.frame.DataFrame) – forecasted dataframe with timeseries data
ts (TSDataset) – dataframe of timeseries that was used for backtest
feature (Union[str, Literal['timestamp']]) – feature name to draw against residuals, if “timestamp” plot residuals against the timestamp
transforms (Sequence[Transform]) – sequence of transforms to get feature column
segments (Optional[List[str]]) – segments to use
columns_num (int) – number of columns in subplots
figsize (Tuple[int, int]) – size of the figure per subplot with one segment in inches
- Raises
ValueError: – if feature isn’t present in the dataset after applying transformations
Notes
Parameter
transforms
is necessary because some pipelines doesn’t save features in their forecasts, e.g.etna.ensembles
pipelines.
- prediction_actual_scatter_plot(forecast_df: pandas.core.frame.DataFrame, ts: TSDataset, segments: Optional[List[str]] = None, columns_num: int = 2, figsize: Tuple[int, int] = (10, 5))[source]¶
Plot scatter plot with forecasted/actual values for segments.
- Parameters
forecast_df (pandas.core.frame.DataFrame) – forecasted dataframe with timeseries data
ts (TSDataset) – dataframe of timeseries that was used for backtest
segments (Optional[List[str]]) – segments to plot
columns_num (int) – number of columns in subplots
figsize (Tuple[int, int]) – size of the figure per subplot with one segment in inches
- qq_plot(residuals_ts: TSDataset, qq_plot_params: Optional[Dict[str, Any]] = None, segments: Optional[List[str]] = None, columns_num: int = 2, figsize: Tuple[int, int] = (10, 5))[source]¶
Plot Q-Q plots for segments.
- Parameters
residuals_ts (TSDataset) – dataset with the time series, expected to be the residuals of the model
qq_plot_params (Optional[Dict[str, Any]]) – dictionary with parameters for qq plot,
statsmodels.graphics.gofplots.qqplot()
is usedsegments (Optional[List[str]]) – segments to plot
columns_num (int) – number of columns in subplots
figsize (Tuple[int, int]) – size of the figure per subplot with one segment in inches