<commit_before>bayes
=====

**Bayes** is a small Python class to reason about probabilities.
It uses a Bayesian system to extract features, crunch belief updates and
spew likelihoods back.

`b = Bayes([.5, .5])`: creates a new scenario with two equally likely classes

`b.update([.9, .1])`: updates the scenario with an event that is 9 times more
likely to have happened in the first class

`print(b.most_likely())`: prints which of the two classes is now more likely
  

Example Usage
-------------

```python
print ' -- Spam Filter --'
# Database with number of sightings of each words in (genuine, spam)
# emails.
words_odds = {'buy': (5, 100), 'viagra': (1, 1000), 'meeting': (15, 2)}
# Emails to be analyzed.
emails = [
          "let's schedule a meeting for tomorrow", # 100% genuine (meeting)
          "buy some viagra", # 100% spam (buy, viagra)
          "buy coffee for the meeting", # buy x meeting, should be genuine
         ]

for email in emails:
    # Start with priors of 90% chance being genuine, 10% spam.
    # Probabilities are normalized automatically.
    b = Bayes([('genuine', 90), ('spam', 10)])
    # Update probabilities, using the words in the emails as events and the
    # database of chances to figure out the change.<commit_msg>Include `classify` example in README<commit_after>bayes
=====

**bayes** is a small Python utility to reason about probabilities.
It uses a Bayesian system to extract features, crunch belief updates and
spew likelihoods back. You can use either the high-level functions to
classify instances with supervised learning, or update beliefs manually
with the `Bayes` class.
  
High Level
----------

```python
from bayes import classify, classify_file

spams = ["buy viagra", "dear recipient", "meet sexy singles"] # etc
genuines = ["let's meet tomorrow", "remember to buy milk"]
message = "remember the meeting tomorrow"
print classify(message, {'spam': spams, 'genuine': genuines})
# Classify as "genuine" because of the words "remember" and "tomorrow".

print classify_file("unknown_file", ["java_files", "python_files"])
# Classifies "unknown_file" as either a Python or Java file, considering
# you have directories with examples of each language.
```

Low Level
-------------

```python
from bayes import Bayes

print ' -- Spam Filter --'
# Database with number of sightings of each words in (genuine, spam)
# emails.
words_odds = {'buy': (5, 100), 'viagra': (1, 1000), 'meeting': (15, 2)}
# Emails to be analyzed.
emails = [
          "let's schedule a meeting for tomorrow", # 100% genuine (meeting)
          "buy some viagra", # 100% spam (buy, viagra)
          "buy coffee for the meeting", # buy x meeting, should be genuine
         ]

for email in emails:
    # Start with priors of 90% chance being genuine, 10% spam.
    # Probabilities are normalized automatically.
    b = Bayes([('genuine', 90), ('spam', 10)])
    # Update probabilities, using the words in the emails as events and the
    # database of chances to figure out the change.
{'fraction_non_alphanumeric': 0.11803713527851459, 'fraction_numerical': 0.01889920424403183, 'mean_word_length': 3.6061068702290076, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5227185', 'n_tokens_mistral': 938, 'n_tokens_neox': 842, 'n_words': 398}