Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def calculateJointProbabilities(self, instance):
- """
- Returns the joint distribution over legal labels and the instance.
- Each probability should be stored in the joint counter, e.g.
- Joint[3] = <Estimate of ( P(Label = 3, instance) )>
- To get the list of all possible features or labels, use self.features and
- self.legalLabels.
- """
- joint = util.Counter()
- for label in self.legalLabels:
- # calculate the joint probabilities for each class
- prob = self.prior[label]
- for feat in self.features:
- prob *= self.conditionalProb[(feat, label, instance[feat])]
- joint[label] = prob
- return joint
- def calculateLogJointProbabilities(self, instance):
- """
- Returns the log-joint distribution over legal labels and the instance.
- Each log-probability should be stored in the log-joint counter, e.g.
- logJoint[3] = <Estimate of log( P(Label = 3, instance) )>
- To get the list of all possible features or labels, use self.features and
- self.legalLabels.
- """
- logJoint = util.Counter()
- for label in self.legalLabels:
- #calculate the log joint probabilities for each class
- prob = math.log(self.prior[label])
- for feat in self.features:
- prob += math.log(self.conditionalProb[(feat, label, instance[feat])])
- logJoint[label] = prob
- return logJoint
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement