Click or drag to resize
Accord.NET (logo) ReceiverOperatingCharacteristic Class
Receiver Operating Characteristic (ROC) Curve.
Inheritance Hierarchy
SystemObject
  Accord.Statistics.AnalysisReceiverOperatingCharacteristic

Namespace:  Accord.Statistics.Analysis
Assembly:  Accord.Statistics (in Accord.Statistics.dll) Version: 3.4.0
Syntax
[SerializableAttribute]
public class ReceiverOperatingCharacteristic
Request Example View Source

The ReceiverOperatingCharacteristic type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyActual
Gets the actual values given by the test.
Public propertyArea
Gets the area under this curve (AUC).
Public propertyExpected
Gets the ground truth values, or the values which should have been given by the test if it was perfect.
Public propertyNegativeAccuracies
Gets DeLong's pseudoaccuracies for the negative subjects
Public propertyNegativeResults
Gets the actual test results for subjects which should have been labeled as negative.
Public propertyNegatives
Gets the number of actual negative cases.
Public propertyObservations
Gets the number of cases (observations) being analyzed.
Public propertyPoints
Gets the points of the curve.
Public propertyPositiveAccuracies
Gets DeLong's pseudoaccuracies for the positive subjects.
Public propertyPositiveResults
Gets the actual test results for subjects which should have been labeled as positive.
Public propertyPositives
Gets the number of actual positive cases.
Public propertyStandardError
Gets the standard error for the Area.
Public propertyVariance
Gets the variance of the curve's Area.
Top
Methods
  NameDescription
Public methodCompute(Double)
Computes a ROC curve with 1/increment points
Public methodCompute(Double)
Computes a ROC curve with the given increment points
Public methodCompute(Int32)
Computes a n-points ROC curve.
Public methodCompute(Double, Boolean)
Computes a ROC curve with 1/increment points
Public methodComputePoint
Computes a single point of a ROC curve using the given cutoff value.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetScatterplot
Generates a Scatterplot representing the ROC curve.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodStatic memberLoad(Stream)
Loads a curve from a stream.
Public methodStatic memberLoad(String)
Loads a curve from a file.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodSave(Stream)
Saves the curve to a stream.
Public methodSave(String)
Saves the curve to a stream.
Public methodToString
Returns a String that represents this curve.
(Overrides ObjectToString.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by Matrix.)
Top
Remarks

In signal detection theory, a receiver operating characteristic (ROC), or simply ROC curve, is a graphical plot of the sensitivity vs. (1 − specificity) for a binary classifier system as its discrimination threshold is varied.

This package does not attempt to fit a curve to the obtained points. It just computes the area under the ROC curve directly using the trapezoidal rule.

Also note that the curve construction algorithm uses the convention that a higher test value represents a positive for a condition while computing sensitivity and specificity values.

References:

  • Wikipedia, The Free Encyclopedia. Receiver Operating Characteristic. Available on: http://en.wikipedia.org/wiki/Receiver_operating_characteristic
  • Anaesthesist. The magnificent ROC. Available on: http://www.anaesthetist.com/mnm/stats/roc/Findex.htm

Examples

The following example shows how to measure the accuracy of a binary classifier using a ROC curve.

// This example shows how to measure the accuracy of a 
// binary classifier using a ROC curve. For this example,
// we will be creating a Support Vector Machine trained
// on the following training instances:

double[][] inputs =
{
    // Those are from class -1
    new double[] { 2, 4, 0 },
    new double[] { 5, 5, 1 },
    new double[] { 4, 5, 0 },
    new double[] { 2, 5, 5 },
    new double[] { 4, 5, 1 },
    new double[] { 4, 5, 0 },
    new double[] { 6, 2, 0 },
    new double[] { 4, 1, 0 },

    // Those are from class +1
    new double[] { 1, 4, 5 },
    new double[] { 7, 5, 1 },
    new double[] { 2, 6, 0 },
    new double[] { 7, 4, 7 },
    new double[] { 4, 5, 0 },
    new double[] { 6, 2, 9 },
    new double[] { 4, 1, 6 },
    new double[] { 7, 2, 9 },
};

int[] outputs =
{
    -1, -1, -1, -1, -1, -1, -1, -1, // fist eight from class -1
    +1, +1, +1, +1, +1, +1, +1, +1  // last eight from class +1
};

// Next, we create a linear Support Vector Machine with 4 inputs
SupportVectorMachine machine = new SupportVectorMachine(inputs: 3);

// Create the sequential minimal optimization learning algorithm
var smo = new SequentialMinimalOptimization(machine, inputs, outputs);

// We learn the machine
double error = smo.Run();

// And then extract its predicted labels
double[] predicted = new double[inputs.Length];
for (int i = 0; i < predicted.Length; i++)
    predicted[i] = machine.Compute(inputs[i]);

// At this point, the output vector contains the labels which
// should have been assigned by the machine, and the predicted
// vector contains the labels which have been actually assigned.

// Create a new ROC curve to assess the performance of the model
var roc = new ReceiverOperatingCharacteristic(outputs, predicted);
roc.Compute(100); // Compute a ROC curve with 100 cut-off points

// Generate a connected scatter plot for the ROC curve and show it on-screen
ScatterplotBox.Show(roc.GetScatterplot(includeRandom: true), nonBlocking: true)

    .SetSymbolSize(0)      // do not display data points
    .SetLinesVisible(true) // show lines connecting points
    .SetScaleTight(true)   // tighten the scale to points
    .WaitForClose();

The resulting graph is shown below.

See Also