gt22

Untitled

Oct 9th, 2018
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. from collections import defaultdict
  2.  
  3. def _count_words(self, d):
  4.     ret = defaultdict(lambda: 0)
  5.     for line in d:
  6.         for word in line:
  7.             ret[word] += 1
  8.     return ret
  9.  
  10. def fit(self, x, y):
  11.     spam = x[y == 1]
  12.     ham = x[y == 0]
  13.     spam_words = self._count_words(spam)
  14.     ham_words = self._count_words(ham)
  15.     spam_sum = sum(spam_words.values())
  16.     ham_sum = sum(ham_words.values())
  17.     #........
Advertisement
Add Comment
Please, Sign In to add comment