A memory-based, optional-persistence naïve bayesian text classifier.
Project description
A memory-based, optional-persistence naïve bayesian text classifier.
This work is heavily inspired by the python "redisbayes" module found here: [https://github.com/jart/redisbayes] and [https://pypi.python.org/pypi/redisbayes] I've elected to write this to alleviate the network/time requirements when using the bayesian classifier to classify large sets of text, or when attempting to train with very large sets of sample data.
Installation
sudo pip install simplebayes
Basic Usage
import simplebayes
bayes = simplebayes.SimpleBayes()
bayes.train('good', 'sunshine drugs love sex lobster sloth')
bayes.train('bad', 'fear death horror government zombie')
assert bayes.classify('sloths are so cute i love them') == 'good'
assert bayes.classify('i would fear a zombie and love the government') == 'bad'
print bayes.score('i fear zombies and love the government')
bayes.untrain('bad', 'fear death')
assert bayes.tally('bad') == 3
Cache Usage
import simplebayes
bayes = simplebayes.SimpleBayes(cache_path='/my/cache/')
# Cache file is '/my/cache/_simplebayes.pickle'
# Default cache_path is '/tmp/'
if not bayes.cache_train():
# Unable to load cache data, so we're training it
bayes.train('good', 'sunshine drugs love sex lobster sloth')
bayes.train('bad', 'fear death horror government zombie')
# Saving the cache so next time the training won't be needed
bayes.persist_cache()
Tokenizer Override
import simplebayes
def my_tokenizer(sample):
return sample.split()
bayes = simplebayes.SimpleBayes(tokenizer=my_tokenizer)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
simplebayes-1.5.3.tar.gz
(5.7 kB
view hashes)
Built Distributions
simplebayes-1.5.3-py3.4.egg
(14.9 kB
view hashes)
simplebayes-1.5.3-py2.7.egg
(14.4 kB
view hashes)
Close
Hashes for simplebayes-1.5.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 914263a45748beee7ffad1ebf11721deab0752bf7ce954cf609bbcdeb49611df |
|
MD5 | db573958c9f4cdb2467ebafb0ff4e369 |
|
BLAKE2b-256 | f46da6934902df7f637377e44089e701f03da11d481b27c12ea65121538e3798 |