Advertisement
Guest User

Untitled

a guest
Nov 16th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1.  
  2. emoticons = [":'(", ";)", ":p", ":s", "(:"]
  3. def get_w_w_e(doc,emo):
  4. words = set()
  5. for word in re.split('\\W+', doc):
  6. if 2 < len(word) < 20:
  7. words.add(word.lower())
  8. for word in re.split(' ',doc):
  9. if word in emo:
  10. words.add(word)
  11. return words
  12. def helper_fun(doc):
  13. return get_w_w_e(doc,emoticons)
  14. if __name__ == '__main__':
  15. sample_ind = int(input())
  16. test_case=data.pop(sample_ind)
  17. c1=NaiveBayes(get_words)
  18. c2=NaiveBayes(helper_fun)
  19. for x in data:
  20. c1.train(x[1],x[0])
  21. c2.train(x[1],x[0])
  22. print(test_case[1])
  23. print(f'Vistinska klasa: {test_case[0]}')
  24. print(f'Klasa predvidena so Naiven Baes (bez emotikoni): {c1.classify_document(test_case[1])}')
  25. print(f'Klasa predvidena so Naiven Baes (so emotikoni): {c2.classify_document(test_case[1])}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement