22
  • I have tried the Orange Framework for Naive Bayesian classification.

    • The methods are extremely unintuitive, and the documentation is extremely unorganized. Does anyone here have another framework to recommend?
    • I use mostly NaiveBayesian for now.
  • I was thinking of using nltk's NaiveClassification but then they don't think they can handle continuous variables.

What are my options?

smci
  • 32,567
  • 20
  • 113
  • 146
disappearedng
  • 493
  • 1
  • 7
  • 12

6 Answers6

25

The scikit-learn has an implementation of Gaussian naive Bayesian classifier. In general, the goal of this library is to provide a good trade off between code that is easy to read and use, and efficiency. Hopefully it should be a good library to learn of the algorithms work.

rgbrgb
  • 1,146
  • 1
  • 11
  • 17
Gael Varoquaux
  • 2,466
  • 2
  • 24
  • 12
13

This might be a good place to start. It's the full source code (the text parser, the data storage, and the classifier) for a python implementation of of a naive Bayesian classifier. Although it's complete, it's still small enough to digest in one session. I think the code is reasonably well written and well commented. This is part of the source code files for the book Programming Collective Intelligence.

To get the source, click the link, dl and unpack the zip, from the main folder 'PCI_Code', go to the folder 'chapter 6', which has a python source file 'docclass.py. That's the complete source code for a Bayesian spam filter. The training data (emails) are persisted in an sqlite database which is also included in the same folder ('test.db') The only external library you need are the python bindings to sqlite (pysqlite); you also need sqlite itself if you don't already have it installed).

doug
  • 69,080
  • 24
  • 165
  • 199
  • 1
    Can I also add a plug for Toby's book, which is excellent. If you are using his source code, it might be good to support him! Most importantly, this file shows that a Naive Bayes system, if you remove all the SQL handling, is only a few lines long. If you're looking for a small one, you could very simply make your own. The significant functions are just `fprob` and `weightedprob` and `naivebayes.classify` – Ian Nov 20 '11 at 21:23
  • I found the source code in Programming Collective Intelligence to be terrible (possibly because it was written in an old, and uglier, version of Python). Despite the ugly code, I highly recommend the book for an introduction to machine learning. – Buttons840 Jan 06 '14 at 21:44
  • 1
    The link to download is broken. Does anyone know the new link? – krasnaya Sep 16 '14 at 20:37
9

If you're processing natural language, check out the Natural Language Toolkit.

If you're looking for something else, here's a simple search on PyPI.

pebl appears to handle continuous variables.

André Paramés
  • 934
  • 9
  • 23
Hank Gay
  • 70,339
  • 36
  • 160
  • 222
  • Is there something that you know of which allows continuous variables? – disappearedng Apr 05 '10 at 20:03
  • The [pebl tutorial](http://ano.malo.us/pebl/docs/tutorial.html) covers discretizing, so I assume it can handle continuous variables via that method, at least. – Hank Gay Apr 05 '10 at 20:24
3

I found Divmod Reverend to be the simplest and easiest to use Python Bayesian classifier.

Cerin
  • 60,957
  • 96
  • 316
  • 522
2

I just took Paul Graham's LISP stuff and converted to to Python http://www.paulgraham.com/spam.html

Ryan Nowakowski
  • 811
  • 7
  • 10
0

There’s also SpamBayes, which I think can be used as a general naive Bayesian clasisfier, instead of just for spam.

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270