Class BernoulliNaiveBayes


  • public class BernoulliNaiveBayes
    extends BaseNaiveBayes
    Naive Bayes classifier for bernoulli distributed models.
    • Constructor Detail

      • BernoulliNaiveBayes

        public BernoulliNaiveBayes()
    • Method Detail

      • jointLogLikelihood

        protected NumpyArray<Double> jointLogLikelihood​(NumpyArray<Double> x)
        Compute the unnormalized posterior log probability of X.

        I.e. ``log P(c) + log P(x|c)`` for all rows x of X, as an array-like of shape (n_samples, n_classes).

        predict, predictProbabilities, and predictLogProbabilities pass the input over to jointLogLikelihood.

        Specified by:
        jointLogLikelihood in class BaseNaiveBayes
        Parameters:
        x - An array-like of shape (n_samples, n_classes).
        Returns:
        The unnormalized posterior log probability of X.
      • getFeatureLogProbabilities

        public NumpyArray<Double> getFeatureLogProbabilities()
        Gets the empirical log probability of features given a class, P(x_i|y).
        Returns:
        Empirical log probability of features given a class, P(x_i|y).
      • setFeatureLogProbabilities

        public void setFeatureLogProbabilities​(NumpyArray<Double> featureLogProbabilities)
        Sets the empirical log probability of features given a class, P(x_i|y).
        Parameters:
        featureLogProbabilities - The empirical log probability of features given a class, P(x_i|y).
      • getClassLogPrior

        public NumpyArray<Double> getClassLogPrior()
        Gets the log probability of each class (smoothed).
        Returns:
        Log probability of each class (smoothed).
      • setClassLogPrior

        public void setClassLogPrior​(NumpyArray<Double> classLogPrior)
        Sets the log probability of each class (smoothed).
        Parameters:
        classLogPrior - The log probability of each class (smoothed).
      • getFeatureCounts

        public NumpyArray<Double> getFeatureCounts()
        Gets the number of samples encountered for each (class, feature) during fitting. This value is weighted by the sample weight when provided.
        Returns:
        Number of samples encountered for each (class, feature) during fitting. This value is weighted by the sample weight when provided.
      • setFeatureCount

        public void setFeatureCount​(NumpyArray<Double> featureCounts)
        Sets the number of samples encountered for each (class, feature) during fitting. This value is weighted by the sample weight when provided.
        Parameters:
        featureCounts - The number of samples encountered for each (class, feature) during fitting. This value is weighted by the sample weight when provided.
      • getBinarizationThreshold

        public double getBinarizationThreshold()
        Gets the threshold for binarizing (mapping to booleans) of sample features. If None, input is presumed to already consist of binary vectors.
        Returns:
        Threshold for binarizing (mapping to booleans) of sample features. If None, input is presumed to already consist of binary vectors.
      • setBinarizationThreshold

        public void setBinarizationThreshold​(double binarizationThreshold)
        Sets the threshold for binarizing (mapping to booleans) of sample features. If None, input is presumed to already consist of binary vectors.
        Parameters:
        binarizationThreshold - The threshold for binarizing (mapping to booleans) of sample features. If None, input is presumed to already consist of binary vectors.