Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import defaultdict
- def _count_words(self, d):
- ret = defaultdict(lambda: 0)
- for line in d:
- for word in line:
- ret[word] += 1
- return ret
- def fit(self, x, y):
- spam = x[y == 1]
- ham = x[y == 0]
- spam_words = self._count_words(spam)
- ham_words = self._count_words(ham)
- spam_sum = sum(spam_words.values())
- ham_sum = sum(ham_words.values())
- #........
Advertisement
Add Comment
Please, Sign In to add comment