new PredictionCurve(yTrue, yPred)

Class implements several prediction curve measures (ROC, AOC, Precision-Recall, ...).

Example

// import metrics module
var metrics = require('qminer').analytics.metrics;

// true and predicted lables
var true_lables = [0, 1, 0, 0, 1];
var pred_prob = [0.3, 0.5, 0.2, 0.5, 0.8];

// create predictionCurve instance
var predictionCurve = new metrics.PredictionCurve();

// simulate data flow
for (var i in true_lables) {
   // push new value
   predictionCurve.push(true_lables[i], pred_prob[i]);
}

var roc = predictionCurve.roc(); // get ROC
var auc = predictionCurve.auc(); // get AUC
var pr = predictionCurve.precisionRecallCurve() // get precision-recall curve

Parameters

Name Type Optional Description

yTrue

(Array of number or module:la.Vector)

 

Ground truth (correct) lable(s) of binary classification in range {-1, 1} or {0, 1}.

yPred

(Array of number or module:la.Vector)

 

Estimated probabilities.

Properties

allNegatives  number

Count of all negative examples.

allPositives  number

Count of all positive examples.

grounds  module:la.Vector

Store of ground truths.

length  number

Count of all examples.

predictions  module:la.Vector

Store of predictions.

Methods

auc([sample]) → number

Get Area Under the Curve (AUC) of the current curve.

Parameter

Name Type Optional Description

sample

number

Yes

Desired number of samples in output.

Defaults to 10.

Returns

numberB Area under ROC curve.

bestF1() → number

Gets threshold for prediction score, which results in the highest F1.

Returns

numberB Threshold with highest F1 score.

breakEvenPoint() → number

Get break-even point, the value where precision and recall intersect.

Returns

numberB Break-even point.

desiredPrecision(desiredPrecision) → number

Gets threshold for prediction score, nearest to specified precision.

Parameter

Name Type Optional Description

desiredPrecision

number

 

Desired precision score.

Returns

numberB Threshold for prediction score, nearest to specified precision.

desiredRecall(desiredRecall) → number

Gets threshold for prediction score, nearest to specified recall.

Parameter

Name Type Optional Description

desiredRecall

number

 

Desired recall score.

Returns

numberB Recal Score Threshold. Threshold for recall score, nearest to specified recall.

precisionRecallCurve([sample]) → module:la.Matrix

Get precision recall curve sampled on sample points.

Parameter

Name Type Optional Description

sample

number

Yes

Desired number of samples in output.

Defaults to 10.

Returns

module:la.MatrixB Precision-recall pairs.

push(ground, predicted)

Add new measurement with ground score (1 or -1) and predicted value or integer array (when there are zero or more then one lables).

Parameters

Name Type Optional Description

ground

number

 

Correct lable.

predicted

number

 

Estimated probabilities.

roc([sample]) → module:la.Matrix

Get Receiver Operating Characteristic (ROC) parametrization sampled on sample points.

Parameter

Name Type Optional Description

sample

number

Yes

Desired number of samples in output.

Defaults to 10.

Returns

module:la.MatrixB A matrix with increasing false and true positive rates.