class_docstr: The Gaussian Naive Bayes classifier. 
class_docstr_tok: ["The","Gaussian","Naive","Bayes","classifier","."]
docstr: Classification using Bayes Rule P(Y|X) = P(X|Y)*P(Y)/P(X),
      or Posterior = Likelihood * Prior / Scaling Factor
  
  P(Y|X) - The posterior is the probability that sample x is of class y given the
           feature values of x being distributed according to distribution of y and the prior.
  P(X|Y) - Likelihood of data X given class distribution Y.
           Gaussian distribution (given by _calculate_likelihood)
  P(Y)   - Prior (given by _calculate_prior)
  P(X)   - Scales the posterior to make it a proper probability distribution.
           This term is ignored in this implementation since it doesn't affect
           which class distribution the sample is most likely to belong to.
  
  Classifies the sample as the class that results in the largest P(Y|X) (posterior)
docstr_tok: ["Classification","using","Bayes","Rule","P","(","Y|X",")","=","P","(","X|Y",")","*","P","(","Y",")","\/P","(","X",")",",","or","Posterior","=","Likelihood","*","Prior","\/","Scaling","Factor","P","(","Y|X",")","-","The","posterior","is","the","probability","that","sample","x","is","of","class","y","given","the","feature","values","of","x","being","distributed","according","to","distribution","of","y","and","the","prior",".","P","(","X|Y",")","-","Likelihood","of","data","X","given","class","distribution","Y.","Gaussian","distribution","(","given","by","_calculate_likelihood",")","P","(","Y",")","-","Prior","(","given","by","_calculate_prior",")","P","(","X",")","-","Scales","the","posterior","to","make","it","a","proper","probability","distribution",".","This","term","is","ignored","in","this","implementation","since","it","does","n't","affect","which","class","distribution","the","sample","is","most","likely","to","belong","to",".","Classifies","the","sample","as","the","class","that","results","in","the","largest","P","(","Y|X",")","(","posterior",")"]
code: def _classify(self, sample):
      """Classification using Bayes Rule P(Y|X) = P(X|Y)*P(Y)/P(X),
          or Posterior = Likelihood * Prior / Scaling Factor
  
      P(Y|X) - The posterior is the probability that sample x is of class y given the
               feature values of x being distributed according to distribution of y and the prior.
      P(X|Y) - Likelihood of data X given class distribution Y.
               Gaussian distribution (given by _calculate_likelihood)
      P(Y)   - Prior (given by _calculate_prior)
      P(X)   - Scales the posterior to make it a proper probability distribution.
               This term is ignored in this implementation since it doesn't affect
               which class distribution the sample is most likely to belong to.
  
      Classifies the sample as the class that results in the largest P(Y|X) (posterior)
      """
      posteriors = []
      # Go through list of classes
      for i, c in enumerate(self.classes):
          # Initialize posterior as prior
          posterior = self._calculate_prior(c)
          # Naive assumption (independence):
          # P(x1,x2,x3|Y) = P(x1|Y)*P(x2|Y)*P(x3|Y)
          # Posterior is product of prior and likelihoods (ignoring scaling factor)
          for feature_value, params in zip(sample, self.parameters[i]):
              # Likelihood of feature value given distribution of feature values given y
              likelihood = self._calculate_likelihood(
                  params["mean"], params["var"], feature_value
              )
              posterior *= likelihood
          posteriors.append(posterior)
      # Return the class with the largest posterior probability
      return self.classes[np.argmax(posteriors)]
  
file_path: ML-From-Scratch/mlfromscratch/supervised_learning/naive_bayes.py
imports: from __future__ import division, print_function
  import numpy
  import math
  from mlfromscratch.utils import train_test_split, normalize
  from mlfromscratch.utils import Plot, accuracy_score
label_desc: Use image node_id 4 for calling the NaiveBayes obj's underlying member method code with example usage: obj._classify(sample) and returns: self