ramjet.analysis.roc_calculator

Code for a class to calculate receiver operating characteristic (ROC) curves.

Module Contents

class RocCalculator[source]

A class to calculate receiver operating characteristic (ROC) curves.

true_positive_rates :np.ndarray

Calculates the true positive rates for the accumulated confusion matrix counts for each threshold.

Returns:The true positive rates for each threshold.
false_positive_rates :np.ndarray

Calculates the false positive rates for the accumulated confusion matrix counts for each threshold.

Returns:The false positive rates for each threshold.
__init__(self)[source]
static threshold_predictions(probability_predictions: np.ndarray, thresholds: np.ndarray)[source]

From a 1D array of probability predictions, calculates a 2D array of binary predictions with each row corresponding to the predictions given one of the passed probability thresholds.

Parameters:
  • probability_predictions – The array of predicted probabilities for the binary labels.
  • thresholds – The thresholds to generate binary labels on from the probabilities.
Returns:

The array containing the binary labels for each threshold.

static calculate_confusion_matrix_counts(label: np.ndarray, predictions: np.ndarray)[source]

Calculates the confusion matrix counts for a 1D set of true binary labels a 2D array of predictions, where each row corresponds to a prediction to compare.

Parameters:
  • label – A 1D binary array label.
  • predictions – A 2D array of predictions, each row of which is to be compared to the label.
Returns:

The confusion matrix values for each row of the predictions.

accumulate_confusion_matrix_counts(self, label: np.ndarray, prediction: np.ndarray)[source]

Calculates the confusion matrix counts for a given label and probability prediction pair, and adds those counts to the totals.

Parameters:
  • label – The 1D array binary label.
  • prediction – The 1D probability array prediction.
generate_roc_plot(self, output_path: Union[str, Path] = 'roc_curve.svg', title: str = None)[source]

Generates a ROC curve plot from the confusion matrix totals which have been accumulated.

Parameters:
  • output_path – The path to save the plot image file to.
  • title – The title to add to the plot.