Class MultiClassNaiveBayes

  • All Implemented Interfaces:
    java.io.Serializable

    public class MultiClassNaiveBayes
    extends java.lang.Object
    implements java.io.Serializable
    Multi-class Naive Bayes text classifier
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      MultiClassNaiveBayes()
      Creates MultiClassNaiveBayes classifier
      MultiClassNaiveBayes​(int maxSamples)
      Create MultiClassNaiveBayes classifier
      MultiClassNaiveBayes​(int maxSamples, int maxTextLength)
      Create MultiClassNaiveBayes classifier
      MultiClassNaiveBayes​(int maxSamples, int maxTextLength, double alpha)
      Creates MultiClassNaiveBayes classifier
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addSample​(java.lang.String category, java.lang.String text)
      Adds training sample for the classifier
      java.util.List<Classification> classify​(java.lang.String text)
      Classifies the input text
      void removeCategory​(java.lang.String category)
      Removes a category from the training data
      void reset()
      Resets the classifier into initial state
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MultiClassNaiveBayes

        public MultiClassNaiveBayes()
        Creates MultiClassNaiveBayes classifier
      • MultiClassNaiveBayes

        public MultiClassNaiveBayes​(int maxSamples)
        Create MultiClassNaiveBayes classifier
        Parameters:
        maxSamples - the maximum number of training samples
      • MultiClassNaiveBayes

        public MultiClassNaiveBayes​(int maxSamples,
                                    int maxTextLength)
        Create MultiClassNaiveBayes classifier
        Parameters:
        maxSamples - the maximum number of training samples
        maxTextLength - the maximum length of input text for the classifier
      • MultiClassNaiveBayes

        public MultiClassNaiveBayes​(int maxSamples,
                                    int maxTextLength,
                                    double alpha)
        Creates MultiClassNaiveBayes classifier
        Parameters:
        maxSamples - the maximum number of training samples
        maxTextLength - the maximum length of input text for the classifier
        alpha - the additional smoothing term. For the so-called Lidstone smoothing alpha < 1.0 and for Laplace smoothing alpha == 1.
    • Method Detail

      • addSample

        public void addSample​(@NonNull
                              java.lang.String category,
                              @NonNull
                              java.lang.String text)
        Adds training sample for the classifier
        Parameters:
        category - the classified category of the text. It corresponds to context id
        text - the input text.
      • removeCategory

        public void removeCategory​(@NonNull
                                   java.lang.String category)
        Removes a category from the training data
        Parameters:
        category - the category (i.e. context id)
      • classify

        public java.util.List<Classification> classify​(@NonNull
                                                       java.lang.String text)
        Classifies the input text
        Parameters:
        text - the input text to be classified
        Returns:
        the list of possible classifications with probability values
      • reset

        public void reset()
        Resets the classifier into initial state