Class: ROC

Inherits:
Object
  • Object
show all
Defined in:
lib/rroc.rb

Overview

This class provides methods for Reciever Operating Characteristic (ROC) curve calculation; algorithm copied from the ML-Mathematica mathematica library by Steven Bedrick ([email protected]). For an excellent overview of ROC analysis, check out:

Fawcett, T. “An introduction to ROC analysis” Pattern Recognition Letters 27 (2006) 861-874 (pdf)

first col of mat is discrim. val; second col is label (+1 -> pos, -1 -> neg, higher disc. val -> more pos)

e.g.: [[.3, -1], [.7, 1], [.1, -1] . . . ]

The scale of first column is not important. The labels in the second column are.

pts plot fpr (x-axis) against tpr (y-axis)

Class Method Summary collapse

Class Method Details

.auc(dat) ⇒ Fixnum

Calculates the “area under the ROC curve” for the output of a binary classifier.

Parameters:

  • dat (Array)

    Classifier output for which the AUC should be calculated, in the form of a n x 2 matrix. Each row represents a “case” (document, example, etc.); the first column is the discriminant value, and the second column must be either -1 (if the ground truth class of the case is “negative”) or 1 (if the ground truth is “positive”).

Returns:

  • (Fixnum)

    The “area under the ROC” curve.



19
20
21
# File 'lib/rroc.rb', line 19

def self.auc(dat)
  return self.calc(dat, false)
end

.curve_points(dat) ⇒ Array

Returns a set of x/y coordinates describing an ROC curve for dat plotting the FPR on the abscissa and the TPR on the ordinate.

Parameters:

  • dat (Array)

    Classifier output for which the AUC should be calculated, in the form of a n x 2 matrix. Each row represents a “case” (document, example, etc.); the first column is the discriminant value, and the second column must be either -1 (if the ground truth class of the case is “negative”) or 1 (if the ground truth is “positive”).

Returns:

  • (Array)

    x/y coordinates that, when plotted, illustrate an ROC curve for dat. Each element in the array is an array containing an x and y coordinate.



26
27
28
# File 'lib/rroc.rb', line 26

def self.curve_points(dat)
  return self.calc(dat, true)[:points]
end