Make the regression's shuffle seed an argument with no default
This commit is contained in:
@@ -65,7 +65,7 @@ def words_of(text: str) -> frozenset[str]:
|
||||
return frozenset(words) | {f"{first} {second}" for first, second in zip(words, words[1:])}
|
||||
|
||||
|
||||
def logistic(samples: typing.Sequence[Sample], seed: int = 0) -> typing.Callable[[str], float]:
|
||||
def logistic(samples: typing.Sequence[Sample], seed: int) -> typing.Callable[[str], float]:
|
||||
"""The chance that a message is an interrupt, from a logistic regression over its words that the samples train, shuffled in the order seed gives."""
|
||||
seen = collections.Counter(word for found in samples for word in words_of(found.text))
|
||||
vocabulary = {word for word, count in seen.items() if count >= MIN_MESSAGES}
|
||||
|
||||
@@ -60,11 +60,11 @@ class DecisionTable(unittest.TestCase):
|
||||
|
||||
class Logistic(unittest.TestCase):
|
||||
def test_gives_a_message_with_no_learned_word_about_the_share_of_interrupts(self):
|
||||
chance = logistic([sample(INTERRUPTED, "")] * 10 + [sample(FINISHED, "")] * 30)
|
||||
chance = logistic([sample(INTERRUPTED, "")] * 10 + [sample(FINISHED, "")] * 30, 0)
|
||||
self.assertAlmostEqual(chance(""), 0.25, delta=0.05)
|
||||
|
||||
def test_learns_a_word_found_in_as_few_messages_as_the_minimum(self):
|
||||
chance = logistic([sample(INTERRUPTED, "ask")] * 3 + [sample(FINISHED, "")] * 3)
|
||||
chance = logistic([sample(INTERRUPTED, "ask")] * 3 + [sample(FINISHED, "")] * 3, 0)
|
||||
self.assertGreater(chance("ask"), chance(""))
|
||||
|
||||
def test_averaged_is_the_mean_of_the_regressions_that_shuffle_in_each_seed_order(self):
|
||||
|
||||
Reference in New Issue
Block a user