Class CategoricalNaiveBayes


  • public class CategoricalNaiveBayes
    extends BaseNaiveBayes
    Naive Bayes classifier for categorical features.

    The categorical Naive Bayes classifier is suitable for classification with discrete features that are categorically distributed. The categories of each feature are drawn from a categorical distribution.

    • Constructor Detail

      • CategoricalNaiveBayes

        public CategoricalNaiveBayes()
    • 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).
      • 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).
      • getFeatureLogProbabilities

        public List<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​(List<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).