bff.plot.plot_predictions

bff.plot.plot_predictions(y_true, y_pred, x_true=None, x_pred=None, label_true='Actual', label_pred='Predicted', label_x='x', label_y='y', title='Model predictions', ax=None, loc='best', rotation_xticks=None, grid='y', figsize=14, 5, dpi=80, style='default', **kwargs)

Plot the predictions of the model.

If a DataFrame is provided, it must only contain one column.

Parameters
  • y_true (np.array, pd.Series or pd.DataFrame) – Actual values.

  • y_pred (np.array, pd.Series or pd.DataFrame) – Predicted values by the model.

  • x_true (np.array, pd.Series, pd.DataFrame, optional) – X coordinates for actual values. If not given, will be integer starting from 0.

  • x_pred (np.array, pd.Series, pd.DataFrame, optional) – X coordinates for predicted values. If not given, will be integer starting from 0.

  • label_true (str, default 'Actual') – Label for the actual values.

  • label_pred (str, default 'Predicted') – Label for the predicted values.

  • label_x (str, default 'x') – Label for x axis.

  • label_y (str, default 'y') – Label for y axis.

  • title (str, default 'Model predictions') – Title for the plot (axis level).

  • ax (plt.axes, default None) – Axes from matplotlib, if None, new figure and axes will be created.

  • loc (str or int, default 'best') – Location of the legend on the plot. Either the legend string or legend code are possible.

  • rotation_xticks (float, optional) – Rotation of x ticks if any. Set to 90 to put them vertically.

  • grid (str or None, default 'y') – Axis where to activate the grid (‘both’, ‘x’, ‘y’). To turn off, set to None.

  • figsize (Tuple[int, int], default (14, 5)) – Size of the figure to plot.

  • dpi (int, default 80) – Resolution of the figure.

  • style (str, default 'default') – Style to use for matplotlib.pyplot. The style is use only in this context and not applied globally.

  • **kwargs – Additional keyword arguments to be passed to the plt.plot function from matplotlib.

Returns

Axes returned by the plt.subplots function.

Return type

plt.axes

Examples

>>> y_pred = model.predict(x_test, ...)
>>> plot_predictions(y_true, y_pred, title='MyTitle', linestyle=':')