Documentation of 'jsat.classifiers.bayesian.MultinomialNaiveBayes' Java class
MultinomialNaiveBayes
jsat.classifiers.bayesian

Class MultinomialNaiveBayes

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Classifier, UpdateableClassifier, Parameterized


    public class MultinomialNaiveBayes
    extends BaseUpdateableClassifier
    implements Parameterized
    An implementation of the Multinomial Naive Bayes model (MNB). In this model, vectors are implicitly assumed to be sparse and that zero values can be skipped. This model requires that all numeric features be non negative, any negative value will be treated as a zero.

    Note: the is no reason to ever use more than one epoch for MNB

    MNB requires taking the log probabilities to perform predictions, which created a trade off. Updating the classifier requires the non log form, but updates require the log form, making classification take considerably longer to take the logs of the probabilities. This can be reduced by finalizing the model. This prevents the model from being updated further, but reduces classification time. By default, this will be done after a call to train(jsat.classifiers.ClassificationDataSet) but not after update(jsat.classifiers.DataPoint, int)
    See Also:
    Serialized Form
    • Constructor Detail

      • MultinomialNaiveBayes

        public MultinomialNaiveBayes()
        Creates a new Multinomial model with laplace smoothing
      • MultinomialNaiveBayes

        public MultinomialNaiveBayes(double smoothing)
        Creates a new Multinomial model with the given amount of smoothing
        Parameters:
        smoothing - the amount of smoothing to apply
    • Method Detail

      • setSmoothing

        public void setSmoothing(double smoothing)
        Sets the amount of smoothing applied to the model.
        Using a value of 1.0 is equivalent to laplace smoothing

        The smoothing can be changed after the model has already been trained without needed to re-train the model for the change to take effect.
        Parameters:
        smoothing - the positive smoothing constant
      • getSmoothing

        public double getSmoothing()
        Returns:
        the smoothing applied to categorical counts
      • setFinalizeAfterTraining

        public void setFinalizeAfterTraining(boolean finalizeAfterTraining)
        If set true, the model will be finalized after a call to train(jsat.classifiers.ClassificationDataSet). This prevents the model from being updated in an online fashion for an reduction in classification time.
        Parameters:
        finalizeAfterTraining - true to finalize after a call to train, false to keep the model updatable.
      • isFinalizeAfterTraining

        public boolean isFinalizeAfterTraining()
        Returns true if the model will be finalized after batch training. false if it will be left in an updatable state.
        Returns:
        true if the model will be finalized after batch training.
      • train

        public void train(ClassificationDataSet dataSet,
                          boolean parallel)
        Description copied from interface: Classifier
        Trains the classifier and constructs a model for classification using the given data set. If the training method knows how, it will used the threadPool to conduct training in parallel. This method will block until the training has completed.
        Specified by:
        train in interface Classifier
        Overrides:
        train in class BaseUpdateableClassifier
        Parameters:
        dataSet - the data set to train on
        parallel - true if multiple threads should be used to train the model. false if it should be done in a single threaded manner.
      • update

        public void update(DataPoint dataPoint,
                           int targetClass)
        Description copied from interface: UpdateableClassifier
        Updates the classifier by giving it a new data point to learn from.
        Specified by:
        update in interface UpdateableClassifier
        Parameters:
        dataPoint - the data point to learn
        targetClass - the target class of the data point
      • classify

        public CategoricalResults classify(DataPoint data)
        Description copied from interface: Classifier
        Performs classification on the given data point.
        Specified by:
        classify in interface Classifier
        Parameters:
        data - the data point to classify
        Returns:
        the results of the classification.
      • supportsWeightedData

        public boolean supportsWeightedData()
        Description copied from interface: Classifier
        Indicates whether the model knows how to train using weighted data points. If it does, the model will train assuming the weights. The values returned by this method may change depending on the parameters set for the model.
        Specified by:
        supportsWeightedData in interface Classifier
        Returns:
        true if the model supports weighted data, false otherwise

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.