ir.classifiers
Class Classifier

java.lang.Object
  extended by ir.classifiers.Classifier
Direct Known Subclasses:
NaiveBayes, Perceptron

public abstract class Classifier
extends java.lang.Object

Abstract class specifying the functionality of a classifier. Provides methods for training and testing a classifier


Field Summary
protected  java.lang.String[] categories
          Array of categories (classes) in the data
protected static java.util.Random random
          Used for breaking ties in argMax()
 
Constructor Summary
Classifier()
           
 
Method Summary
protected  int argMax(double[] results)
          Returns the array index with the maximum value
 java.lang.String[] getCategories()
          Returns the categories (classes) in the data
abstract  java.lang.String getName()
          The name of a classifier
abstract  boolean test(Example testExample)
          Returns true if the predicted category of the test example matches the correct category, false otherwise
abstract  void train(java.util.List<Example> trainingExamples)
          Trains the classifier on the training examples
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

random

protected static java.util.Random random
Used for breaking ties in argMax()


categories

protected java.lang.String[] categories
Array of categories (classes) in the data

Constructor Detail

Classifier

public Classifier()
Method Detail

getName

public abstract java.lang.String getName()
The name of a classifier

Returns:
the name of a particular classifier

getCategories

public java.lang.String[] getCategories()
Returns the categories (classes) in the data

Returns:
an array containing strings describing the categories

train

public abstract void train(java.util.List<Example> trainingExamples)
Trains the classifier on the training examples

Parameters:
trainingExamples - a list of Example objects that will be used for training the classifier

test

public abstract boolean test(Example testExample)
Returns true if the predicted category of the test example matches the correct category, false otherwise


argMax

protected int argMax(double[] results)
Returns the array index with the maximum value

Parameters:
results - Array of doubles whose index with max value is to be found. Ties are broken randomly.