received_operating_characteristic#

rojak.turbulence.metrics.received_operating_characteristic(sorted_truth: Array, sorted_values: Array, num_intervals: int = 100, positive_classification_label: int | float | bool | str | None = None) BinaryClassificationResult[source]#

Received operating characteristic or ROC curve

This method is a dask-friendly implementation of sklearn.metrics.roc_curve()

Parameters:
Return type:

BinaryClassificationResult

Returns:

Modifying the example in the scikit-learn documentation on roc_curves:

>>> import dask.array as da
>>> y = np.asarray([1, 1, 2, 2])
>>> scores = np.asarray([0.1, 0.4, 0.35, 0.8])
>>> received_operating_characteristic(da.asarray(y), da.asarray(scores), positive_classification_label=2)
Traceback (most recent call last):
ValueError: values must be strictly decreasing
>>> decrease_idx = np.argsort(scores)[::-1]
>>> scores = da.asarray(scores[decrease_idx])
>>> y = da.asarray(y[decrease_idx])
>>> roc = received_operating_characteristic(y, scores, positive_classification_label=2)
>>> roc
BinaryClassificationResult(false_positives=dask.array<truediv, shape=(5,), dtype=float64, chunksize=(3,),
chunktype=numpy.ndarray>, true_positives=dask.array<truediv, shape=(5,), dtype=float64, chunksize=(3,),
chunktype=numpy.ndarray>, thresholds=dask.array<concatenate, shape=(5,), dtype=float64, chunksize=(3,),
chunktype=numpy.ndarray>)
>>> roc.false_positives.compute()
array([0. , 0. , 0.5, 0.5, 1. ])
>>> roc.true_positives.compute()
array([0. , 0.5, 0.5, 1. , 1. ])
>>> roc.thresholds.compute()
array([ inf, 0.8 , 0.4 , 0.35, 0.1 ])

see binary_classification_curve() for a more detailed explanation of doc test