Created
December 7, 2010 05:16
-
-
Save kvorion/731492 to your computer and use it in GitHub Desktop.
classify method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Classify(self, featureVector): #featureVector is a simple list like the ones that we use to train | |
probabilityPerLabel = {} #store the final probability for each class label | |
for label in self.labelCounts: | |
logProb = 0 | |
for featureValue in featureVector: | |
logProb += math.log(self.featureCounts[(label, self.featureNameList[featureVector.index(featureValue)], featureValue)]/self.labelCounts[label]) | |
probabilityPerLabel[label] = (self.labelCounts[label]/sum(self.labelCounts.values())) * math.exp(logProb) | |
print probabilityPerLabel | |
return max(probabilityPerLabel, key = lambda classLabel: probabilityPerLabel[classLabel]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment