edu.stanford.nlp.stats
Class PrecisionRecallStats

java.lang.Object
  extended by edu.stanford.nlp.stats.PrecisionRecallStats

public class PrecisionRecallStats
extends java.lang.Object

Utility class for aggregating counts of true positives, false positives, and false negatives and computing precision/recall/F1 stats. Can be used for a single collection of stats, or to aggregate stats from a bunch of runs.

Author:
Joseph Smarr

Field Summary
protected  int fnCount
          Count of false negatives.
protected  int fpCount
          Count of false positives.
protected  int tpCount
          Count of true positives.
 
Constructor Summary
PrecisionRecallStats()
          Constructs a new PrecisionRecallStats with initially 0 counts.
PrecisionRecallStats(Classifier<L,F> classifier, Dataset<L,F> data, L positiveClass)
           
PrecisionRecallStats(int tp, int fp, int fn)
          Constructs a new PrecisionRecallStats with the given initial counts.
 
Method Summary
 void addCounts(PrecisionRecallStats prs)
          Adds the counts from the given stats to the counts of this stats.
 void addFN(int count)
          Adds the given number to the count of false negatives.
 void addFP(int count)
          Adds the given number to the count of false positives.
 void addTP(int count)
          Adds the given number to the count of true positives.
 java.lang.String getF1Description(int numDigits)
          Returns a String summarizing F1 that will print nicely.
 double getFMeasure()
          Returns the current F1 measure (alpha=0.5).
 double getFMeasure(double alpha)
          Returns the F-Measure with the given mixing parameter (must be between 0 and 1).
 int getFN()
          Returns the current count of false negatives.
 int getFP()
          Returns the current count of false positives.
 double getPrecision()
          Returns the current precision: tp/(tp+fp).
 java.lang.String getPrecisionDescription(int numDigits)
          Returns a String summarizing precision that will print nicely.
 double getRecall()
          Returns the current recall: tp/(tp+fn).
 java.lang.String getRecallDescription(int numDigits)
          Returns a String summarizing recall that will print nicely.
 int getTP()
          Returns the current count of true positives.
 void incrementFN()
          Adds one to the count of false negatives.
 void incrementFP()
          Adds one to the count of false positives.
 void incrementTP()
          Adds one to the count of true positives.
 java.lang.String toString()
          Returns a String representation of this PrecisionRecallStats, indicating the number of tp, fp, fn counts.
 java.lang.String toString(int numDigits)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

tpCount

protected int tpCount
Count of true positives.


fpCount

protected int fpCount
Count of false positives.


fnCount

protected int fnCount
Count of false negatives.

Constructor Detail

PrecisionRecallStats

public PrecisionRecallStats()
Constructs a new PrecisionRecallStats with initially 0 counts.


PrecisionRecallStats

public PrecisionRecallStats(Classifier<L,F> classifier,
                            Dataset<L,F> data,
                            L positiveClass)

PrecisionRecallStats

public PrecisionRecallStats(int tp,
                            int fp,
                            int fn)
Constructs a new PrecisionRecallStats with the given initial counts.

Method Detail

getTP

public int getTP()
Returns the current count of true positives.


getFP

public int getFP()
Returns the current count of false positives.


getFN

public int getFN()
Returns the current count of false negatives.


addTP

public void addTP(int count)
Adds the given number to the count of true positives.


incrementTP

public void incrementTP()
Adds one to the count of true positives.


addFP

public void addFP(int count)
Adds the given number to the count of false positives.


incrementFP

public void incrementFP()
Adds one to the count of false positives.


addFN

public void addFN(int count)
Adds the given number to the count of false negatives.


incrementFN

public void incrementFN()
Adds one to the count of false negatives.


addCounts

public void addCounts(PrecisionRecallStats prs)
Adds the counts from the given stats to the counts of this stats.


getPrecision

public double getPrecision()
Returns the current precision: tp/(tp+fp). Returns 1.0 if tp and fp are both 0.


getPrecisionDescription

public java.lang.String getPrecisionDescription(int numDigits)
Returns a String summarizing precision that will print nicely.


getRecall

public double getRecall()
Returns the current recall: tp/(tp+fn). Returns 1.0 if tp and fn are both 0.


getRecallDescription

public java.lang.String getRecallDescription(int numDigits)
Returns a String summarizing recall that will print nicely.


getFMeasure

public double getFMeasure()
Returns the current F1 measure (alpha=0.5).


getFMeasure

public double getFMeasure(double alpha)
Returns the F-Measure with the given mixing parameter (must be between 0 and 1). If either precision or recall are 0, return 0.0. F(alpha) = 1/(alpha/precision + (1-aalpha)/recall)


getF1Description

public java.lang.String getF1Description(int numDigits)
Returns a String summarizing F1 that will print nicely.


toString

public java.lang.String toString()
Returns a String representation of this PrecisionRecallStats, indicating the number of tp, fp, fn counts.

Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(int numDigits)


Stanford NLP Group