fairscoring.plots#

Plots to visualize and analyze different bias metrics

Submodules#

Functions#

plot_groupwise_score_calibration(scores, target, ...)

Plot groupwise score calibration.

plot_groupwise_cdfs(scores, target, attribute, groups, ...)

Plot groupwise cumulative distributions functions (cdfs).

plot_cdf_diffs(scores, target, attribute, groups, ...)

Plots the difference between two cumulative distributions functions (cdfs).

Package Contents#

fairscoring.plots.plot_groupwise_score_calibration(scores, target, attribute, groups, favorable_target, *, ax=None, palette=sns.color_palette(), n_bins=20, n_bootstrap=10, rescale=True, rescale_by=None, prefer_high_scores=True, strategy='uniform')#

Plot groupwise score calibration. Calibration plots. Optional with bootstrap curves.

Parameters:
  • scores (ArrayLike) – A list of scores

  • target (ArrayLike) – The binary target values. Must have the same length as scores.

  • attribute (ndarray) – The protected attribute. Must have the same length as scores.

  • groups (list) – A list of groups. Each group is given by a value of the protected attribute. A value of None is used to define a group with all elements that are not in another group.

  • favorable_target (str or int) – The favorable outcome.

  • ax (matplotlib.axes.Axes, optional) – The axes into which the calibration curves shall be plotted

  • palette (list or Colormap, Optional) – Color palette, number of colors must at least be number of groups

  • n_bins (int, Default=20) – (Maximal) number of bins

  • n_bootstrap (int, optional, Default=10) – Number of bootstrap samples; can be slow for large datasets. Set to None, to disable bootstrapping.

  • rescale_by (List, optional) – Maximum and minimum possible score value for rescaling. If None, the minimum and maximum from the data are used.

  • rescale (bool, default=True) – True if the values are rescaled.

  • prefer_high_scores (bool, optional) – Specify whether high scores or low scores are favorable.

  • strategy ({'uniform', 'quantiles'}) – Strategy to determine bins

See also

fairscoring.metrics.CalibrationMetric, sklearn.calibration.calibration_curve

fairscoring.plots.plot_groupwise_cdfs(scores, target, attribute, groups, favorable_target, *, ax=None, palette=sns.color_palette(), fairness_type, quantile_transform=True, prefer_high_scores=True)#

Plot groupwise cumulative distributions functions (cdfs).

Parameters:
  • scores (ArrayLike) – A list of scores

  • target (ArrayLike) – The binary target values. Must have the same length as scores.

  • attribute (ndarray) – The protected attribute. Must have the same length as scores.

  • groups (list) –

    A list of groups. Each group is given by a value of the protected attribute. A value of None is used to define a group with all elements that are not in another group.

    __Note__: Currently, only plots with exactly two groups are possible.

  • favorable_target (str or int) – The favorable outcome.

  • ax (matplotlib.axes.Axes, optional) – The axes into which the cdfs shall be plotted

  • palette (list or Colormap, Optional) – Color palette, number of colors must at least be number of groups

  • fairness_type ({"IND", "EO", "PE"}) – Specifies the type of fairness that is measured. Accepted values are: 1. “IND” (Independence), 2. “EO” (Equal Opportunity), 3. “PE” (Predictive Equality),

  • quantile_transform (bool, default=True) – Specify whether the scores shall be quantile transformed.

  • prefer_high_scores (bool, default=True) – Specify whether high scores or low scores are favorable.

fairscoring.plots.plot_cdf_diffs(scores, target, attribute, groups, favorable_target, *, ax=None, palette=sns.color_palette(), fairness_type, quantile_transform=True, prefer_high_scores=True)#

Plots the difference between two cumulative distributions functions (cdfs).

Parameters:
  • scores (ArrayLike) – A list of scores

  • target (ArrayLike) – The binary target values. Must have the same length as scores.

  • attribute (ndarray) – The protected attribute. Must have the same length as scores.

  • groups (list) –

    A list of groups. Each group is given by a value of the protected attribute. A value of None is used to define a group with all elements that are not in another group.

    __Note__: There must be exactly two groups to plot the differences.

  • favorable_target (str or int) – The favorable outcome.

  • ax (matplotlib.axes.Axes, optional) – The axes into which the cdfs shall be plotted

  • palette (list or Colormap, Optional) – Color palette, number of colors must at least be number of groups

  • fairness_type ({"IND", "EO", "PE"}) – Specifies the type of fairness that is measured. Accepted values are: 1. “IND” (Independence), 2. “EO” (Equal Opportunity), 3. “PE” (Predictive Equality),

  • quantile_transform (bool, default=True) – Specify whether the scores shall be quantile transformed.

  • prefer_high_scores (bool, default=True) – Specify whether high scores or low scores are favorable.