Probabilistic-Programming-and-Bayesian-Methods-for-Hackers README

The project's README from github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers. As one markdown file: README.md.

Bayesian Methods for Hackers

Using Python and PyMC

The Bayesian method is the natural approach to inference, yet it is hidden from readers behind chapters of slow, mathematical analysis. The typical text on Bayesian inference involves two to three chapters on probability theory, then enters what Bayesian inference is. Unfortunately, due to mathematical intractability of most Bayesian models, the reader is only shown simple, artificial examples. This can leave the user with a so-what feeling about Bayesian inference. In fact, this was the author's own prior opinion.

After some recent success of Bayesian methods in machine-learning competitions, I decided to investigate the subject again. Even with my mathematical background, it took me three straight-days of reading examples and trying to put the pieces together to understand the methods. There was simply not enough literature bridging theory to practice. The problem with my misunderstanding was the disconnect between Bayesian mathematics and probabilistic programming. That being said, I suffered then so the reader would not have to now. This book attempts to bridge the gap.

If Bayesian inference is the destination, then mathematical analysis is a particular path towards it. On the other hand, computing power is cheap enough that we can afford to take an alternate route via probabilistic programming. The latter path is much more useful, as it denies the necessity of mathematical intervention at each step, that is, we remove often-intractable mathematical analysis as a prerequisite to Bayesian inference. Simply put, this latter computational path proceeds via small intermediate jumps from beginning to end, where as the first path proceeds by enormous leaps, often landing far away from our target. Furthermore, without a strong mathematical background, the analysis required by the first path cannot even take place.

Bayesian Methods for Hackers is designed as an introduction to Bayesian inference from a computational/understanding-first, and mathematics-second, point of view. Of course as an introductory book, we can only leave it at that: an introductory book. For the mathematically trained, they may cure the curiosity this text generates with other texts designed with mathematical analysis in mind. For the enthusiast with less mathematical background, or one who is not interested in the mathematics but simply the practice of Bayesian methods, this text should be sufficient and entertaining.

The choice of PyMC as the probabilistic programming language is two-fold. As of this writing, there is currently no central resource for examples and explanations in the PyMC universe. The official documentation assumes prior knowledge of Bayesian inference and probabilistic programming. We hope this book encourages users at every level to look at PyMC. Secondly, with recent core developments and popularity of the scientific stack in Python, PyMC is likely to become a core component soon enough.

PyMC does have dependencies to run, namely NumPy and (optionally) SciPy. To not limit the user, the examples in this book will rely only on PyMC, NumPy, SciPy and Matplotlib.

Printed Version by Addison-Wesley

Bayesian Methods for Hackers is now available as a printed book! You can pick up a copy on Amazon. What are the differences between the online version and the printed version?

Contents

See the project homepage here for examples, too.

The below chapters are rendered via the nbviewer at nbviewer.jupyter.org/, and is read-only and rendered in real-time. Interactive notebooks + examples can be downloaded by cloning!

PyMC2

PyMC3

More questions about PyMC? Please post your modeling, convergence, or any other PyMC question on cross-validated, the statistics stack-exchange.

Using the book

The book can be read in three different ways, starting from most recommended to least recommended:

  1. The most recommended option is to clone the repository to download the .ipynb files to your local machine. If you have Jupyter installed, you can view the chapters in your browser plus edit and run the code provided (and try some practice questions). This is the preferred option to read this book, though it comes with some dependencies.

    • Jupyter is a requirement to view the ipynb files. It can be downloaded here. Jupyter notebooks can be run by (your-virtualenv) ~/path/to/the/book/Chapter1_Introduction $ jupyter notebook
    • For Linux users, you should not have a problem installing NumPy, SciPy, Matplotlib and PyMC. For Windows users, check out pre-compiled versions if you have difficulty.
    • In the styles/ directory are a number of files (.matplotlirc) that used to make things pretty. These are not only designed for the book, but they offer many improvements over the default settings of matplotlib.
  2. The second, preferred, option is to use the nbviewer.jupyter.org site, which display Jupyter notebooks in the browser (example). The contents are updated synchronously as commits are made to the book. You can use the Contents section above to link to the chapters.

  3. PDFs are the least-preferred method to read the book, as PDFs are static and non-interactive. If PDFs are desired, they can be created dynamically using the nbconvert utility.

Installation and configuration

If you would like to run the Jupyter notebooks locally, (option 1. above), you'll need to install the following:

Development

This book has an unusual development design. The content is open-sourced, meaning anyone can be an author. Authors submit content or revisions using the GitHub interface.

How to contribute

What to contribute?

Commiting

Reviews

these are satirical, but real

"No, but it looks good" - John D. Cook

"I ... read this book ... I like it!" - Andrew Gelman

"This book is a godsend, and a direct refutation to that 'hmph! you don't know maths, piss off!' school of thought... The publishing model is so unusual. Not only is it open source but it relies on pull requests from anyone in order to progress the book. This is ingenious and heartening" - excited Reddit user

Contributions and Thanks

Thanks to all our contributing authors, including (in chronological order):

Authors
Cameron Davidson-Pilon Stef Gibson Vincent Ohprecio Lars Buitinck
Paul Magwene Matthias Bussonnier Jens Rantil y-p
Ethan Brown Jonathan Whitmore Mattia Rigotti Colby Lemon
Gustav W Delius Matthew Conlen Jim Radford Vannessa Sabino
Thomas Bratt Nisan Haramati Robert Grant Matthew Wampler-Doty
Yaroslav Halchenko Alex Garel Oleksandr Lysenko liori
ducky427 Pablo de Oliveira Castro sergeyfogelson Mattia Rigotti
Matt Bauman Andrew Duberstein Carsten Brandt Bob Jansen
ugurthemaster William Scott Min RK Bulwersator
elpres Augusto Hack Michael Feldmann Youki
Jens Rantil Kyle Meyer Eric Martin Inconditus
Kleptine Stuart Layton Antonino Ingargiola vsl9
Tom Christie bclow Simon Potter Garth Snyder
Daniel Beauchamp Philipp Singer gbenmartin Peadar Coyle

We would like to thank the Python community for building an amazing architecture. We would like to thank the statistics community for building an amazing architecture.

Similarly, the book is only possible because of the PyMC library. A big thanks to the core devs of PyMC: Chris Fonnesbeck, Anand Patil, David Huard and John Salvatier.

One final thanks. This book was generated by Jupyter Notebook, a wonderful tool for developing in Python. We thank the IPython/Jupyter community for developing the Notebook interface. All Jupyter notebook files are available for download on the GitHub repository.

Contact

Contact the main author, Cam Davidson-Pilon at [email protected] or @cmrndp

Imgur

Probabilistic-Programming-and-Bayesian-Methods-for-Hackers (CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers)

Searching Database…

这是什么?一本开源的入门书《Bayesian Methods for Hackers》,用纯 Python 配合 PyMC 讲解贝叶斯推断和概率编程,全书围绕可以直接运行的 Jupyter 笔记本章节展开。
这是一本用来读的书,还是一个用来写代码调用的 Python 库?是一本书,不是库:仓库里放着 PyMC2 和 PyMC3 两个版本、各六章的笔记本版,供你阅读和运行。另外亚马逊上还有 Addison-Wesley 出版的纸质版出售。
推荐的阅读方式是什么?克隆仓库,在本地用 Jupyter 运行各个 .ipynb 章节——这是最推荐的方式。你也可以在浏览器里到 nbviewer.jupyter.org 只读阅读各章节,或者用 nbconvert 生成静态 PDF(最不推荐,因为 PDF 没法交互)。
想自己运行这些笔记本,需要装哪些东西?查看笔记本需要 Jupyter,代码方面需要 PyMC、NumPy、SciPy 和 Matplotlib——示例只用到了这些。做数据挖掘练习时,另外推荐装上 PRAW 和 requests。
我用的是 Windows,配置这些笔记本会很麻烦吗?Linux 和 OS X 用户基本没问题,不过 Matplotlib 在 OSX 上有时比较难缠;如果安装这套科学计算工具包遇到困难,Windows 用户可以下载预编译好的版本。
需要很扎实的数学基础才能看懂吗?不需要——这本书刻意采取先上机理解、数学第二的路线,数学功底不深的读者也能动手实践贝叶斯方法。它明确定位为一本入门书,数学功底好的读者则被引导去其他教材追求严谨。
各章节用了哪些真实世界的例子?全都是贴近实际的例子:从短信频率变化推断行为改变、找出考试作弊的学生、挑战者号航天飞机事故、对 Reddit 评论排序、包括 Dark World 获胜方案在内的 Kaggle 竞赛、《The Price is Right》的最后对决环节,还有多臂老虎机问题。
纸质书和免费在线版有什么区别?Addison-Wesley 的纸质版增加了一章关于贝叶斯 A/B 测试的内容,更新了示例,补充了章节末尾习题的答案,并重写了部分讲解。在线版依然免费开源。
为什么采用计算优先的路线,而不是经典的数学分析?作者曾连续花三天时间从满是数学公式的教材里拼凑贝叶斯方法,不想让读者再受这个罪:如今计算成本很低,通过概率编程就能掌握贝叶斯推断,不必在每一步都啃难懂的数学。
Size
168 MB
Stars
28.2K
Updated
CommitFeb 14
Age
13y
Commits · 90 Days