/** * @param thresholdSteps Number of threshold steps to use for the ROC calculation. If set to 0: use exact calculation * @param rocRemoveRedundantPts Usually set to true. If true, remove any redundant points from ROC and P-R curves * @param exactAllocBlockSize if using exact mode, the block size relocation. Users can likely use the default * setting in almost all cases */ public ROC(int thresholdSteps, boolean rocRemoveRedundantPts, int exactAllocBlockSize) { if (thresholdSteps > 0) { this.thresholdSteps = thresholdSteps; double step = 1.0 / thresholdSteps; for (int i = 0; i <= thresholdSteps; i++) { double currThreshold = i * step; counts.put(currThreshold, new CountsForThreshold(currThreshold)); } isExact = false; } else { //Exact isExact = true; } this.rocRemoveRedundantPts = rocRemoveRedundantPts; this.exactAllocBlockSize = exactAllocBlockSize; }
thresholdCounts.incrementTruePositive(truePositiveCount); thresholdCounts.incrementFalsePositive(falsePositiveCount);
double t = entry.getKey(); CountsForThreshold c = entry.getValue(); long tpCount = c.getCountTruePositive(); long fpCount = c.getCountFalsePositive(); thresholdOut[i] = c.getThreshold(); precisionOut[i] = precision; recallOut[i] = recall;
for (Map.Entry<Double, CountsForThreshold> entry : counts.entrySet()) { CountsForThreshold c = entry.getValue(); double tpr = c.getCountTruePositive() / ((double) countActualPositive); double fpr = c.getCountFalsePositive() / ((double) countActualNegative); out[0][i] = c.getThreshold(); out[1][i] = fpr; out[2][i] = tpr;
@Override public void reset() { countActualPositive = 0L; countActualNegative = 0L; counts.clear(); if (isExact) { probAndLabel = null; } else { double step = 1.0 / thresholdSteps; for (int i = 0; i <= thresholdSteps; i++) { double currThreshold = i * step; counts.put(currThreshold, new CountsForThreshold(currThreshold)); } } exampleCount = 0; auc = null; auprc = null; }
@Override public CountsForThreshold clone() { return new CountsForThreshold(threshold, countTruePositive, countFalsePositive); } }