Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
drwnClassificationResults Class Reference

Encapsulates summary of classifier output from which various curves can be generated (e.g., precision-recall curves). More...

Inheritance diagram for drwnClassificationResults:
drwnPRCurve

Public Member Functions

 drwnClassificationResults ()
 default constructor
 
 drwnClassificationResults (const drwnClassificationResults &c)
 copy constructor
 
int numPositives () const
 return the number os positive samples accumulated
 
int numNegatives () const
 return the number of negative samples accumulated
 
int numSamples () const
 return the total number (positive and negative) of samples accumulated
 
int numThresholds () const
 return the number of unique classification scores
 
int numMisses () const
 return the number of positive samples that have not been scored
 
double getPosWeight () const
 return the relative weight of a positive sample to a negative sample
 
void setPosWeight (double w)
 set the relative weight of a positive sample to a negative sample
 
void normalize ()
 this will change the weight of the positive examples such that overall positive and negative examples will have the same weight
 
void clear ()
 clear the accumulated scores
 
bool write (const char *filename) const
 write the accumulated scores to file
 
bool read (const char *filename)
 read accumulated scores from file
 
void accumulate (const drwnClassificationResults &c)
 accumulate results from another drwnClassificationResults object
 
void accumulate (const drwnClassifierDataset &dataset, drwnClassifier const *classifier, int positiveClassId=1)
 Accumulate results from a classifier run on a dataset. The positiveClass parameter indicates the positive class label for multi-class classifiers.
 
void accumulatePositives (double score, int count=1)
 accumulate a single positive example
 
void accumulatePositives (const vector< double > &scores)
 accumulate multiple positive examples
 
void accumulateNegatives (double score, int count=1)
 accumulate a single negative example
 
void accumulateNegatives (const vector< double > &scores)
 accumulate multiple negative examples
 
void accumulateMisses (int count=1)
 accumulate unscored positive examples (misses)
 

Static Public Attributes

static bool INCLUDE_MISSES = false
 true if some positive samples are never scored
 

Protected Attributes

map< double, pair< int, int > > _scoredResults
 number of positives (first) and negatives (second) grouped by score
 
int _numPositiveSamples
 must be greater than sum(_scoredResults.first)
 
int _numNegativeSamples
 must be must be equal to sum(_scoredResults.second)
 
double _posWeight
 weight of positive-to-negative count
 

Detailed Description

Encapsulates summary of classifier output from which various curves can be generated (e.g., precision-recall curves).

The results can be scored arbitrarily so long as higher score implies more likely. Positive and negative samples can be weighted differently. The following code snippet shows how to produce a precision-recall curve that can be subsequently plotted in Matlab.

vector<int> y = getGroundTruthLabels();
vector<double> y_hat = getPredictionProbabilities();
for (int n = 0; n < N; n++) {
if (y[n] == 1) curve.accumulatePositives(y_hat[n]);
else curve.accumulateNegatives(y_hat[n]);
}
curve.writeCurve("pr.txt");
See Also
drwnPRCurve, drwnML Tutorial

The documentation for this class was generated from the following files: