weka.classifiers.misc
Class Prototype

java.lang.Object
  extended byweka.classifiers.Classifier
      extended byweka.classifiers.DistributionClassifier
          extended byweka.classifiers.misc.Prototype
All Implemented Interfaces:
java.lang.Cloneable, OptionHandler, java.io.Serializable, WeightedInstancesHandler

public class Prototype
extends DistributionClassifier
implements WeightedInstancesHandler, OptionHandler

Class for building and using a simple prototype classifier. Computes an average/mean/prototype vector for each class. New examples are classified based on computing distance from the instance feature vector to the closest prototype. For real-valued attributes, standard vector mean and Euclidian distance are used. To handle nominal attributes, the distribution of values for each category are computed (as in naive Bayes) as part of the prototype. The distance along a nominal attribute from an instance with a value V for this attribute to the prototype for a given class is then: 1- P(V|class) In order to make each attribute contribute equally to the distance, values are normalized to [0,1] by setting NormalizeAttributes, which is set by default Predicted class probabilities to make a DistributionClassifier are assumed to be inversely proportional to the distances from the prototypes Borrows some structure from NaiveBayesSimple

See Also:
Serialized Form

Field Summary
protected  double[][][] m_Counts
          All the counts for nominal attributes.
protected  Instances m_Instances
          The instances used for training.
protected  double[][] m_Means
          The means for numeric attributes.
protected  boolean m_NormalizeAttributes
          If set, Normalize all real attribute values between 0 and 1 so that each dimension contributes equally to distance
protected  double[] m_Ranges
          The range (from min to max) taken on by each of the numeric attributes
 
Constructor Summary
Prototype()
           
 
Method Summary
 void buildClassifier(Instances instances)
          Generates the classifier.
 double[] distributionForInstance(Instance instance)
          Calculates the class membership probabilities for the given test instance.
 boolean getNormalizeAttributes()
           
 java.lang.String[] getOptions()
          Gets the current settings.
 java.lang.String globalInfo()
          Returns a string describing this clusterer
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options..
static void main(java.lang.String[] argv)
          Main method for testing this class.
 java.lang.String normalizeAttributesTipText()
           
 void setNormalizeAttributes(boolean v)
           
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 java.lang.String toString()
          Returns a description of the classifier.
 
Methods inherited from class weka.classifiers.DistributionClassifier
calculateEntropy, calculateLabeledInstanceMargin, calculateMargin, classifyInstance
 
Methods inherited from class weka.classifiers.Classifier
forName, makeCopies
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_Counts

protected double[][][] m_Counts
All the counts for nominal attributes.


m_Means

protected double[][] m_Means
The means for numeric attributes.


m_Ranges

protected double[] m_Ranges
The range (from min to max) taken on by each of the numeric attributes


m_Instances

protected Instances m_Instances
The instances used for training.


m_NormalizeAttributes

protected boolean m_NormalizeAttributes
If set, Normalize all real attribute values between 0 and 1 so that each dimension contributes equally to distance

Constructor Detail

Prototype

public Prototype()
Method Detail

listOptions

public java.util.Enumeration listOptions()
Returns an enumeration describing the available options..

Specified by:
listOptions in interface OptionHandler
Returns:
an enumeration of all the available options.

setOptions

public void setOptions(java.lang.String[] options)
                throws java.lang.Exception
Parses a given list of options.

Specified by:
setOptions in interface OptionHandler
Parameters:
options - the list of options as an array of strings
Throws:
java.lang.Exception - if an option is not supported

getOptions

public java.lang.String[] getOptions()
Gets the current settings.

Specified by:
getOptions in interface OptionHandler
Returns:
an array of strings suitable for passing to setOptions()

setNormalizeAttributes

public void setNormalizeAttributes(boolean v)

getNormalizeAttributes

public boolean getNormalizeAttributes()

normalizeAttributesTipText

public java.lang.String normalizeAttributesTipText()

globalInfo

public java.lang.String globalInfo()
Returns a string describing this clusterer

Returns:
a description of the evaluator suitable for displaying in the explorer/experimenter gui

buildClassifier

public void buildClassifier(Instances instances)
                     throws java.lang.Exception
Generates the classifier.

Specified by:
buildClassifier in class Classifier
Parameters:
instances - set of instances serving as training data
Throws:
java.lang.Exception - if the classifier has not been generated successfully

distributionForInstance

public double[] distributionForInstance(Instance instance)
                                 throws java.lang.Exception
Calculates the class membership probabilities for the given test instance.

Specified by:
distributionForInstance in class DistributionClassifier
Parameters:
instance - the instance to be classified
Returns:
predicted class probability distribution
Throws:
java.lang.Exception - if distribution can't be computed

toString

public java.lang.String toString()
Returns a description of the classifier.

Returns:
a description of the classifier as a string.

main

public static void main(java.lang.String[] argv)
Main method for testing this class.

Parameters:
argv - the options