orbit.diagnostics package

Submodules

orbit.diagnostics.plot module

orbit.diagnostics.plot.get_arviz_plot_dict(mod, incl_noise_params=False, incl_trend_params=False, incl_smooth_params=False)

This is a utility to prepare the plotting dictionary data for package arviz. arviz will interpret each key as the name of a different random variable. Each array should have shape (chains, draws, *shape).

See also

https

//arviz-devs.github.io/arviz/index.html

orbit.diagnostics.plot.metric_horizon_barplot(df, model_col='model', pred_horizon_col='pred_horizon', metric_col='smape', bar_width=0.1, path=None, figsize=None, fontsize=None, is_visible=False)
orbit.diagnostics.plot.plot_bt_predictions(bt_pred_df, metrics=<function smape>, split_key_list=None, ncol=2, figsize=None, include_vline=False, title='', fontsize=20, path=None, is_visible=True)

function to plot and visualize the prediction results from back testing.

bt_pred_dfdata frame

the output of orbit.diagnostics.backtest.BackTester.fit_predict(), which includes the actuals/predictions for all the splits

metricscallable

the metric function

split_key_list: list; default None

with given model, which split keys to plot. If None, all the splits will be plotted

ncolint

number of columns of the panel; number of rows will be decided accordingly

figsizetuple

figure size

include_vlinebool

if plotting the vertical line to cut the in-sample and out-of-sample predictions for each split

titlestr

title of the plot

fontsize: int; optional

fontsize of the title

pathstring

path to save the figure

is_visiblebool

if displaying the figure

orbit.diagnostics.plot.plot_param_diagnostics(mod, incl_noise_params=False, incl_trend_params=False, incl_smooth_params=False, which='trace', **kwargs)
Parameters
  • mod (orbit model object) –

  • which (str, {'density', 'trace', 'pair', 'autocorr', 'posterior', 'forest'}) –

  • incl_noise_params (bool) – if plot noise parameters; default False

  • incl_trend_params (bool) – if plot trend parameters; default False

  • incl_smooth_params (bool) – if plot smoothing parameters; default False

  • **kwargs – other parameters passed to arviz functions

Returns

Return type

matplotlib axes object

orbit.diagnostics.plot.plot_posterior_params(mod, kind='density', n_bins=20, ci_level=0.95, pair_type='scatter', figsize=None, path=None, fontsize=None, incl_trend_params=False, incl_smooth_params=False, is_visible=True)

Data Viz for posterior samples

Parameters
  • mod (orbit model object) –

  • kind (str, {'density', 'trace', 'pair'}) – which kind of plot to be made.

  • n_bins (int; default 20) – number of bin, used in the histogram plotting

  • ci_level (float, between 0 and 1) – confidence interval level

  • pair_type (str, {'scatter', 'reg'}) – dot plotting type for off-diagonal plots in pair plot

  • figsize (tuple; optional) – figure size

  • path (str; optional) – dir path to save the chart

  • fontsize (int; optional) – fontsize of the title

  • incl_trend_params (bool) – if plot trend parameters; default False

  • incl_smooth_params (bool) – if plot smoothing parameters; default False

  • is_visible (boolean) – whether we want to show the plot. If called from unittest, is_visible might = False.

Returns

Return type

matplotlib axes object

orbit.diagnostics.plot.plot_predicted_components(predicted_df, date_col, prediction_percentiles=None, plot_components=None, title='', figsize=None, path=None, fontsize=None, is_visible=True)
Plot predicted components with the data frame of decomposed prediction where components

has been pre-defined as trend, seasonality and regression.

predicted_dfpd.DataFrame

predicted data response data frame. two columns required: actual_col and pred_col. If user provide pred_percentiles_col, it needs to include them as well.

date_colstr

the date column name

prediction_percentileslist

a list should consist exact two elements which will be used to plot as lower and upper bound of confidence interval

plot_componentslist

a list of strings to show the label of components to be plotted; by default, it uses values in orbit.constants.constants.PredictedComponents.

titlestr; optional

title of the plot

figsizetuple; optional

figsize pass through to matplotlib.pyplot.figure()

pathstr; optional

path to save the figure

fontsizeint; optional

fontsize of the title

is_visibleboolean

whether we want to show the plot. If called from unittest, is_visible might = False.

Returns

Return type

matplotlib axes object

orbit.diagnostics.plot.plot_predicted_data(training_actual_df, predicted_df, date_col, actual_col, pred_col='prediction', prediction_percentiles=None, title='', test_actual_df=None, is_visible=True, figsize=None, path=None, fontsize=None, line_plot=False, markersize=70, lw=2, linestyle='-')

Plot training actual response together with predicted data; if actual response of predicted data is there, plot it too.

Parameters
  • training_actual_df (pd.DataFrame) – training actual response data frame. two columns required: actual_col and date_col

  • predicted_df (pd.DataFrame) – predicted data response data frame. two columns required: actual_col and pred_col. If user provide prediction_percentiles, it needs to include them as well in such prediction_{x} where x is the correspondent percentiles

  • prediction_percentiles (list) – list of two elements indicates the lower and upper percentiles

  • date_col (str) – the date column name

  • actual_col (str) –

  • pred_col (str) –

  • title (str) – title of the plot

  • test_actual_df (pd.DataFrame) – test actual response dataframe. two columns required: actual_col and date_col

  • is_visible (boolean) – whether we want to show the plot. If called from unittest, is_visible might = False.

  • figsize (tuple) – figsize pass through to matplotlib.pyplot.figure()

  • path (str) – path to save the figure

  • fontsize (int; optional) – fontsize of the title

  • line_plot (bool; default False) – if True, make line plot for observations; otherwise, make scatter plot for observations

  • markersize (int; optional) – point marker size

  • lw (int; optional) – out-of-sample prediction line width

  • linestyle (str) – linestyle of prediction plot

Returns

Return type

matplotlib axes object

Module contents