xskillscore.roc

xskillscore.roc(observations, forecasts, bin_edges='continuous', dim=None, drop_intermediate=False, return_results='area')

Computes the relative operating characteristic for a range of thresholds.

Parameters
  • observations (xarray.Dataset or xarray.DataArray) – Labeled array(s) over which to apply the function. If bin_edges=='continuous', observations are binary.

  • forecasts (xarray.Dataset or xarray.DataArray) – Labeled array(s) over which to apply the function. If bin_edges=='continuous', forecasts are probabilities.

  • bin_edges (array_like, str, default='continuous') – Bin edges for categorising observations and forecasts. Similar to np.histogram, all but the last (righthand-most) bin include the left edge and exclude the right edge. The last bin includes both edges. bin_edges will be sorted in ascending order. If bin_edges=='continuous', calculate bin_edges from forecasts, equal to sklearn.metrics.roc_curve(f_boolean, o_prob).

  • dim (str, list) – The dimension(s) over which to compute the contingency table

  • drop_intermediate (bool, default=False) – Whether to drop some suboptimal thresholds which would not appear on a plotted ROC curve. This is useful in order to create lighter ROC curves. Defaults to True in sklearn.metrics.roc_curve.

  • return_results (str, default='area') –

    Specify how return is structed:

    • ’area’: return only the area under curve of ROC

    • ’all_as_tuple’: return true positive rate and false positive rate at each bin and area under the curve of ROC as tuple

    • ’all_as_metric_dim’: return true positive rate and false positive rate at each bin and area under curve of ROC concatenated into new metric dimension

Returns

reduced by dimensions dim, see return_results parameter. true positive rate and false positive rate contain probability_bin dimension with ascending bin_edges as coordinates.

Return type

xarray.Dataset or xarray.DataArray

Examples

>>> f = xr.DataArray(np.random.normal(size=(1000)),
...                  coords=[('time', np.arange(1000))])
>>> o = f.copy()
>>> category_edges = np.linspace(-2, 2, 5)
>>> xs.roc(o, f, category_edges, dim=['time'])
<xarray.DataArray 'histogram_observations_forecasts' ()>
array(1.)

References

http://www.cawcr.gov.au/projects/verification/