Package de.jungblut.classification.bayes
Class MultinomialNaiveBayes
- java.lang.Object
-
- de.jungblut.classification.AbstractPredictor
-
- de.jungblut.classification.AbstractClassifier
-
- de.jungblut.classification.bayes.MultinomialNaiveBayes
-
- All Implemented Interfaces:
Classifier,Predictor
public final class MultinomialNaiveBayes extends AbstractClassifier
Multinomial naive bayes classifier. This class now contains a sparse internal representations of the "feature given class" probabilities. So this can be scaled to very large text corpora and large numbers of classes easily. Serialization and deserialization happens through the like-named static methods.- Author:
- thomas.jungblut
-
-
Constructor Summary
Constructors Constructor Description MultinomialNaiveBayes()Default constructor to construct this classifier.MultinomialNaiveBayes(boolean verbose)Pass true if this classifier should output some progress information to STDOUT.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MultinomialNaiveBayesdeserialize(java.io.DataInput in)Deserializes a new MultinomialNaiveBayesClassifier from the given input stream.de.jungblut.math.DoubleVectorpredict(de.jungblut.math.DoubleVector features)Classifies the given features.static voidserialize(MultinomialNaiveBayes model, java.io.DataOutput out)voidtrain(java.lang.Iterable<de.jungblut.math.DoubleVector> features, java.lang.Iterable<de.jungblut.math.DoubleVector> outcome)Trains this classifier with the given features and the outcome.-
Methods inherited from class de.jungblut.classification.AbstractClassifier
train
-
Methods inherited from class de.jungblut.classification.AbstractPredictor
extractPredictedClass, extractPredictedClass, predictedClass, predictedClass, predictProbability
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.jungblut.classification.Predictor
asClassifier, extractPredictedClass, extractPredictedClass, predictedClass, predictedClass, predictProbability
-
-
-
-
Method Detail
-
train
public void train(java.lang.Iterable<de.jungblut.math.DoubleVector> features, java.lang.Iterable<de.jungblut.math.DoubleVector> outcome)Description copied from interface:ClassifierTrains this classifier with the given features and the outcome. This is the streaming method for training, it takes parallel iterables.- Specified by:
trainin interfaceClassifier- Overrides:
trainin classAbstractClassifieroutcome- the outcome must have classes labeled as doubles. E.G. in the binary case you have a single element and decide between 0d and 1d. In higher dimensional cases you have each of these single elements mapped to a dimension.
-
predict
public de.jungblut.math.DoubleVector predict(de.jungblut.math.DoubleVector features)
Description copied from interface:PredictorClassifies the given features.- Returns:
- the vector that contains an indicator at the index of the class. Usually zero or 1, in some cases it is a probability or activation value.
-
deserialize
public static MultinomialNaiveBayes deserialize(java.io.DataInput in) throws java.io.IOException
Deserializes a new MultinomialNaiveBayesClassifier from the given input stream. Note that "in" will not be closed by this method.- Throws:
java.io.IOException
-
serialize
public static void serialize(MultinomialNaiveBayes model, java.io.DataOutput out) throws java.io.IOException
- Throws:
java.io.IOException
-
-