Class 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 Detail

      • MultinomialNaiveBayes

        public MultinomialNaiveBayes()
        Default constructor to construct this classifier.
      • MultinomialNaiveBayes

        public MultinomialNaiveBayes​(boolean verbose)
        Pass true if this classifier should output some progress information to STDOUT.
    • 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: Classifier
        Trains this classifier with the given features and the outcome. This is the streaming method for training, it takes parallel iterables.
        Specified by:
        train in interface Classifier
        Overrides:
        train in class AbstractClassifier
        outcome - 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: Predictor
        Classifies 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