confusion_matrix#

rojak.turbulence.metrics.confusion_matrix(truth: Array, prediction: Array) NDArray[source]#

Compute the confusion matrix

This is a simplified dask-friendly implementation of sklearn.metrics.confusion_matrix() for the binary classification problem.

Parameters:
  • truth (Array) – dask array of shape (n_samples,) Ground truth (correct) target values.

  • prediction (Array) – dask array of shape (n_samples,) Estimated targets as returned by a classifier.

Returns:

Confusion matrix in the order of (tn, fp, fn, tp)

Return type:

NDArray

Examples

This example is modified from the docstring of sklearn.metrics.confusion_matrix()

>>> y_true = da.asarray([0, 1, 0, 1])
>>> y_pred = da.asarray([1, 1, 1, 0])
>>> tn, fp, fn, tp = confusion_matrix(y_true, y_pred).ravel().tolist()
>>> (tn, fp, fn, tp)
(0, 2, 1, 1)

This example is modified from the user guide documentation on confusion matrix:

>>> x_true = da.asarray([0, 0, 0, 1, 1, 1, 1, 1])
>>> x_pred = da.asarray([0, 1, 0, 1, 0, 1, 0, 1])
>>> tn, fp, fn, tp = confusion_matrix(x_true, x_pred).ravel().tolist()
>>> tn, fp, fn, tp
(2, 1, 2, 3)