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. Ifbin_edges=='continuous'
, calculatebin_edges
from forecasts, equal tosklearn.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
insklearn.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
andfalse positive rate
at each bin and area under the curve of ROC as tuple’all_as_metric_dim’: return
true positive rate
andfalse positive rate
at each bin andarea under curve
of ROC concatenated into newmetric
dimension
- Returns
reduced by dimensions
dim
, seereturn_results
parameter.true positive rate
andfalse positive rate
containprobability_bin
dimension with ascendingbin_edges
as coordinates.- Return type
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