fairlearn.metrics._plotter.plot_metric_frame#

fairlearn.metrics._plotter.plot_metric_frame(metric_frame, *, kind='point', metrics=None, conf_intervals=None, subplots=True, plot_ci_labels=False, ci_labels_precision=4, ci_labels_fontsize=8, ci_labels_color='black', ci_labels_ha='center', ci_labels_legend='Conf. Intervals', **kwargs)[source]#

Visualization for metrics with and without confidence intervals.

Plots a given metric and its given error (as described by conf_intervals)

This function takes in a fairlearn.metrics.MetricFrame with precomputed metrics and metric errors and a conf_intervals array to interpret the columns of the fairlearn.metrics.MetricFrame.

The items at each index of the given metrics array and given errors or conf_intervals array should correspond to a pair of the same metric and metric error, respectively.

Parameters:
  • metric_frame (MetricFrame) – The collection of disaggregated metric values, along with the metric errors.

  • kind (str) – The type of plot to display, e.g., “point”, “bar”, “line”, etc. The supported values are “point” and those listed in pandas.DataFrame.plot()

  • metrics (list[str] | str | None) – The name of the metrics to plot. Should match columns from the given fairlearn.metrics.MetricFrame.

  • conf_intervals (list[str] | str | None) –

    The name of the confidence intervals to plot. Should match columns from the given fairlearn.metrics.MetricFrame.

    If None and the metric_frame was created with bootstrap confidence intervals (n_boot and ci_quantiles), they are auto-detected from fairlearn.metrics.MetricFrame.by_group_ci.

    Note:

    The return of the error function should be an array of the lower and upper bounds. e.g. [0.59, 0.62]

  • subplots (bool) – Whether or not to plot metrics on separate subplots

  • plot_ci_labels (bool) – Whether or not to plot numerical labels for the confidence intervals

  • ci_labels_precision (int) – The number of digits of precision to show for confidence interval labels

  • ci_labels_fontsize (int) – The font size to use for confidence interval labels

  • ci_labels_color (str) – The font color to use for confidence interval labels

  • ci_labels_ha (str) – The horizontal alignment modifier to use for confidence interval labels

  • ci_labels_legend (str) – The label corresponding to the confidence interval bars

  • **kwargs – Keyword arguments that are passed in to pandas.DataFrame.plot()

Return type:

matplotlib.axes.Axes or numpy.ndarray of them

Raises:

ValueError – If metric_frame is not a MetricFrame, if metrics is not a string, a list or None, if there are no metrics to plot, if metrics and conf_intervals have different lengths, or if the confidence intervals are not pairs of values with the lower bound not exceeding the upper bound.