weka.classifiers.evaluation
Class NominalPrediction

java.lang.Object
  extended byweka.classifiers.evaluation.NominalPrediction
All Implemented Interfaces:
Prediction, java.io.Serializable

public class NominalPrediction
extends java.lang.Object
implements Prediction, java.io.Serializable

Encapsulates an evaluatable nominal prediction: the predicted probability distribution plus the actual class value.

Version:
$Revision: 1.9 $
Author:
Len Trigg (len@reeltwo.com)
See Also:
Serialized Form

Field Summary
private  double m_Actual
          The actual class value
private  double[] m_Distribution
          The predicted probabilities
private  double m_Predicted
          The predicted class value
private  double m_Weight
          The weight assigned to this prediction
(package private) static long serialVersionUID
          Remove this if you change this class so that serialization would be affected.
 
Fields inherited from interface weka.classifiers.evaluation.Prediction
MISSING_VALUE
 
Constructor Summary
NominalPrediction(double actual, double[] distribution)
          Creates the NominalPrediction object with a default weight of 1.0.
NominalPrediction(double actual, double[] distribution, double weight)
          Creates the NominalPrediction object.
 
Method Summary
 double actual()
          Gets the actual class value.
 double[] distribution()
          Gets the predicted probabilities
static double[] makeDistribution(double predictedClass, int numClasses)
          Convert a single prediction into a probability distribution with all zero probabilities except the predicted value which has probability 1.0.
static double[] makeUniformDistribution(int numClasses)
          Creates a uniform probability distribution -- where each of the possible classes is assigned equal probability.
 double margin()
          Calculates the prediction margin.
 double predicted()
          Gets the predicted class value.
 java.lang.String toString()
          Gets a human readable representation of this prediction.
private  void updatePredicted()
          Determines the predicted class (doesn't detect multiple classifications).
 double weight()
          Gets the weight assigned to this prediction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
Remove this if you change this class so that serialization would be affected.

See Also:
Constant Field Values

m_Distribution

private double[] m_Distribution
The predicted probabilities


m_Actual

private double m_Actual
The actual class value


m_Predicted

private double m_Predicted
The predicted class value


m_Weight

private double m_Weight
The weight assigned to this prediction

Constructor Detail

NominalPrediction

public NominalPrediction(double actual,
                         double[] distribution)
Creates the NominalPrediction object with a default weight of 1.0.

Parameters:
actual - the actual value, or MISSING_VALUE.
distribution - the predicted probability distribution. Use NominalPrediction.makeDistribution() if you only know the predicted value.

NominalPrediction

public NominalPrediction(double actual,
                         double[] distribution,
                         double weight)
Creates the NominalPrediction object.

Parameters:
actual - the actual value, or MISSING_VALUE.
distribution - the predicted probability distribution. Use NominalPrediction.makeDistribution() if you only know the predicted value.
weight - the weight assigned to the prediction.
Method Detail

distribution

public double[] distribution()
Gets the predicted probabilities


actual

public double actual()
Gets the actual class value.

Specified by:
actual in interface Prediction
Returns:
the actual class value, or MISSING_VALUE if no prediction was made.

predicted

public double predicted()
Gets the predicted class value.

Specified by:
predicted in interface Prediction
Returns:
the predicted class value, or MISSING_VALUE if no prediction was made.

weight

public double weight()
Gets the weight assigned to this prediction. This is typically the weight of the test instance the prediction was made for.

Specified by:
weight in interface Prediction
Returns:
the weight assigned to this prediction.

margin

public double margin()
Calculates the prediction margin. This is defined as the difference between the probability predicted for the actual class and the highest predicted probability of the other classes.

Returns:
the margin for this prediction, or MISSING_VALUE if either the actual or predicted value is missing.

makeDistribution

public static double[] makeDistribution(double predictedClass,
                                        int numClasses)
Convert a single prediction into a probability distribution with all zero probabilities except the predicted value which has probability 1.0. If no prediction was made, all probabilities are zero.

Parameters:
predictedClass - the index of the predicted class, or MISSING_VALUE if no prediction was made.
numClasses - the number of possible classes for this nominal prediction.
Returns:
the probability distribution.

makeUniformDistribution

public static double[] makeUniformDistribution(int numClasses)
Creates a uniform probability distribution -- where each of the possible classes is assigned equal probability.

Parameters:
numClasses - the number of possible classes for this nominal prediction.
Returns:
the probability distribution.

updatePredicted

private void updatePredicted()
Determines the predicted class (doesn't detect multiple classifications). If no prediction was made (i.e. all zero probababilities in the distribution), m_Prediction is set to MISSING_VALUE.


toString

public java.lang.String toString()
Gets a human readable representation of this prediction.

Returns:
a human readable representation of this prediction.