示例#1
0
    def classify_messages(self):
        """c
        """
        messages = self.test_messages
        classes = self.classes

        for message in messages:
            if self.agent_type == "spam":
                to_copy = CLASSMAPSPAM
            else:
                to_copy = CLASSMAP8
            MAP_values = deepcopy(to_copy)
            ML_values = deepcopy(to_copy)
            for key in MAP_values:
                aClass = classes[key]
                P_aClass = log(self.p_of_class(aClass))
                MAP_values[key] = P_aClass
                ML_values[key] = 0
            word_dict = message.word_dict
            for word in word_dict:
                for key in classes:
                    pwgc = p_of_word_given_class(
                        word,
                        classes[key]
                    )
                    MAP_values[key] += log(pwgc)
                    ML_values[key] += log(pwgc)
            message.classification =\
                Classification(MAP_values, ML_values)
示例#2
0
def odds(word, class_1, class_2):
    """c
    """
    pwgc1 = p_of_word_given_class(word, class_1)
    pwgc2 = p_of_word_given_class(word, class_2)
    return log(ratio(pwgc1, pwgc2))