Class NaiveBayes

java.lang.Object
ai.beestream.jitnn.ml.NaiveBayes

public final class NaiveBayes extends Object
Naive Bayes classifiers after scikit-learn's GaussianNB (per-class means and variances, the variances smoothed by varSmoothing times the largest feature variance) and MultinomialNB (feature counts with additive smoothing alpha). Class priors are the class frequencies.
  • Constructor Details

    • NaiveBayes

      public NaiveBayes(NaiveBayes.Kind kind, float smoothing)
      smoothing: varSmoothing (Gaussian, scikit-learn's 1e-9) or alpha (multinomial, 1).
  • Method Details

    • fit

      public NaiveBayes fit(Tensor x, int[] y)
      Fits samples x [n, features] (counts for the multinomial kind) and labels y.
    • jointLogLikelihood

      public Tensor jointLogLikelihood(Tensor x)
      Joint log-likelihood [m, c].
    • predictProba

      public Tensor predictProba(Tensor x)
      Class probabilities [n, classes] for samples x.
    • predict

      public int[] predict(Tensor x)
      The most probable label of each sample.
    • theta

      public Tensor theta()
      Gaussian: the per-class feature means [classes, features].
    • var

      public Tensor var()
      Gaussian: the per-class feature variances [classes, features], smoothed.
    • featureLogProb

      public Tensor featureLogProb()
      Multinomial: the per-class log probabilities of the features [classes, features].