Last active
August 29, 2015 13:59
-
-
Save lutzky/10907342 to your computer and use it in GitHub Desktop.
Unit test for add-one Laplace smoothing
This file contains 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 test_p_word(self): | |
e = Evaluator() | |
# Add negative reviews | |
e.add_review(False, {"horrible", "crappy", "boring"}) | |
e.add_review(False, {"awfully", "mediocre"}) | |
e.add_review(False, {"terrible", "boring"}) | |
# Add positive reviews | |
e.add_review(True, {"wonderful", "delightful", "awesome"}) | |
e.add_review(True, {"awesome", "awfully", "thrilling"}) | |
# e.p_word(word, category) should return smoothed P(word | category) | |
self.assertAlmostEquals(e.p_word("unbelievable", True), 1/4) | |
self.assertAlmostEquals(e.p_word("awesome", True), 3/4) | |
self.assertAlmostEquals(e.p_word("boring", False), 3/5) | |
self.assertAlmostEquals(e.p_word("heinous", False), 1/5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment