Bayes Theorem in Python

Alex Martelli aleaxit at yahoo.com
Tue May 22 08:26:14 EDT 2001


"Ron Stephens" <rdsteph at earthlink.net> wrote in message
news:3B08F864.CD9EA4FB at earthlink.net...
> Does anyone know if someone has already coded Bayes theorem into Python?

You mean as in:

def Bayes(P_H, P_E, P_E_given_H):
    P_H_given_E = (P_H * P_E_given_H) / P_E
    return P_H_given_E

...?  I suspect somebody must have already coded one
multiplication and one division into one Python expression,
yes, although it's hard to be sure about the variable
names they may have chosen.  Or do you mean something
completely different...?


> Also, is there a module that includes code for probability calculations
> or regression anlaysis?

Sure.
http://www.nmr.mgh.harvard.edu/Neural_Systems_Group/gary/python.html
has several useful Python modules for statistics.

Chris Rathman's regression.py module is online at:
http://www.angelfire.com/tx4/cus/regress/python.html

http://net.fenx.com/alex/prob.py?lang=e is a sample CGI webpage
to compute and display conditional probabilities of suit
division in the game of bridge, given some partial knowledge
about two hidden hands (the formulas are explained at
http://net.fenx.com/alex/e_cpdt.htm, and include Bayes'
theorem:-), but I forgot to make the Python sources available...
well, the templatization and HTML display part is actually
now published as YAPTU on the Python Cookbook, and the
Bayes theorem computation is at the head of this post, so...:-).

At the other extreme of power and complexity, have a look
at http://www.omegahat.org/.  With the R/SPlus - Python
Interface, you get a thin Python binding over a huge
library of statistical SW (which has its own scripting
language, so the operation isn't as seamless as one might
dream of, but...).


Alex








More information about the Python-list mailing list