SHARE
TWEET

Untitled

a guest May 22nd, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def calculateJointProbabilities(self, instance):
  2.         """
  3.         Returns the joint distribution over legal labels and the instance.
  4.         Each probability should be stored in the joint counter, e.g.
  5.         Joint[3] = <Estimate of ( P(Label = 3, instance) )>
  6.  
  7.         To get the list of all possible features or labels, use self.features and
  8.         self.legalLabels.
  9.         """
  10.         joint = util.Counter()
  11.  
  12.         for label in self.legalLabels:
  13.             # calculate the joint probabilities for each class
  14.             prob = self.prior[label]
  15.             for feat in self.features:
  16.                 prob *= self.conditionalProb[(feat, label, instance[feat])]
  17.             joint[label] = prob
  18.  
  19.         return joint
  20.  
  21.  
  22.     def calculateLogJointProbabilities(self, instance):
  23.         """
  24.         Returns the log-joint distribution over legal labels and the instance.
  25.         Each log-probability should be stored in the log-joint counter, e.g.
  26.         logJoint[3] = <Estimate of log( P(Label = 3, instance) )>
  27.  
  28.         To get the list of all possible features or labels, use self.features and
  29.         self.legalLabels.
  30.         """
  31.         logJoint = util.Counter()
  32.  
  33.         for label in self.legalLabels:
  34.             #calculate the log joint probabilities for each class
  35.             prob = math.log(self.prior[label])
  36.             for feat in self.features:
  37.                 prob += math.log(self.conditionalProb[(feat, label, instance[feat])])
  38.  
  39.             logJoint[label] = prob
  40.  
  41.         return logJoint
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top