Skip to main content

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-hypernode.com/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.

Build Status

https://travis-ci.org/hickeroar/simplebayes.svg?branch=master https://img.shields.io/badge/coverage-100%-brightgreen.svg?style=flat https://img.shields.io/badge/pylint-10.00/10-brightgreen.svg?style=flat https://img.shields.io/badge/flake8-passing-brightgreen.svg?style=flat

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)

License

The MIT License (MIT)

Copyright (c) 2015 Ryan Vennell

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

API Documentation

http://hickeroar.github.io/simplebayes/simplebayes.html

Project details


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.8.tar.gz (6.0 kB view details)

Uploaded Source

Built Distributions

simplebayes-1.5.8-py3.4.egg (15.5 kB view details)

Uploaded Source

simplebayes-1.5.8-py2.py3-none-any.whl (10.7 kB view details)

Uploaded Python 2 Python 3

simplebayes-1.5.8-py2.7.egg (15.1 kB view details)

Uploaded Source

File details

Details for the file simplebayes-1.5.8.tar.gz.

File metadata

  • Download URL: simplebayes-1.5.8.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for simplebayes-1.5.8.tar.gz
Algorithm Hash digest
SHA256 363418c0ef185ac2158ebbd6d8afb45aa997254fcb809a73ed20a7d5dccf8b85
MD5 bd6aa4b42c6810560b63ec73b6c9de0f
BLAKE2b-256 b973764578df72934940d95a8941cbd374b56319562dda72630fc8bfeaefc350

See more details on using hashes here.

File details

Details for the file simplebayes-1.5.8-py3.4.egg.

File metadata

File hashes

Hashes for simplebayes-1.5.8-py3.4.egg
Algorithm Hash digest
SHA256 4cd334d9f152b5003257b355f39eac609ac02a4ab877eff5d10e90be89e302cc
MD5 3d317eb1087db6be5e5442c2017f9c2a
BLAKE2b-256 3a9eeaaeb461aead574e7014af1e1c5ddaa66908e753833a7667680c15cba6b2

See more details on using hashes here.

File details

Details for the file simplebayes-1.5.8-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for simplebayes-1.5.8-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fd434b950f4ab1bfe8686a8c87c41d37d943a651870571addddb6885092547a9
MD5 eb86b22b14c0e129da1418f086f6ab88
BLAKE2b-256 8040952739a8c9ba040a8adaba409d6cd3a7a7ed532a7cf4b9f7c6b39af078f9

See more details on using hashes here.

File details

Details for the file simplebayes-1.5.8-py2.7.egg.

File metadata

File hashes

Hashes for simplebayes-1.5.8-py2.7.egg
Algorithm Hash digest
SHA256 2aff1b2b7bc4c8d4da636941b7a5015e180ddc752fdaa35345a5833aa72c1618
MD5 9be918f873270478ff0427eb91e179d3
BLAKE2b-256 f8f9cf74c51725cdc5fac7c499e423092e14598f611b48b760f5bb8ba2c4754b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page