- Training Systems Using Python Statistical Modeling
- Curtis Miller
- 397字
- 2021-06-24 14:20:47
Conjugate priors for proportions
So, let's see this in action. For data that takes values of either 0 or 1, we're going to use the beta distribution as our conjugate prior. The notation that is used to refer to the beta distribution is B(α, β).
α - 1 can be interpreted as imaginary prior successes, and β - 1 can be interpreted as imaginary prior failures. That's if you have added the data to your dataset—imaginary successes and imaginary failures.
If α = β = 1, then we interpret this as being no prior successes or failures; therefore, every probability of success, θ, is equally likely in some sense. This is referred to as an uninformative prior. Let's now implement this using the following steps:
- First, we're going to import the beta function from scipy.stats; this is the beta distribution. In addition to this, we will import the numpy library and the matplotlib library, as follows:

- We're then going to plot the function and see how it looks, using the following code:

This results in the following output:

So, if we plot β when α=1 and β=1, we end up with a uniform distribution. In some sense, each p is equally likely.
- Now, we will use a=3 and b=3, to indicate two imaginary successes and two imaginary failures, which gives us the following output:

Now, our prior distribution biases our data toward 0.5—in other words, it is equally likely to succeed as it is to fail.
Given a sample size of N, if there are M successes, then the posterior distribution when the prior is β, with the parameters (α, β), will be B (α + M, β + N - M). So, let's reconsider an earlier example; we have a website with 1,126 visitors. 310 clicked on an ad purchased by a sponsor, and we want to know what proportion of individuals will click on the ad in general.
- So, we're going to use our prior distribution beta (3, 3). This means that the posterior distribution will be given by the beta distribution, with the first parameter, 313, and the second parameter, 819. This is what the prior distribution and posterior distribution looks like when plotted against each other:

The blue represents the prior distribution, and red represents the posterior distribution.
- Apache Oozie Essentials
- GeoServer Cookbook
- Java EE 6 企業級應用開發教程
- Java異步編程實戰
- Python爬蟲開發:從入門到實戰(微課版)
- Django Design Patterns and Best Practices
- 零基礎學Java(第4版)
- 基于Swift語言的iOS App 商業實戰教程
- Web程序設計(第二版)
- Java EE 7 Performance Tuning and Optimization
- Getting Started with Laravel 4
- Android開發:從0到1 (清華開發者書庫)
- Visual FoxPro程序設計習題集及實驗指導(第四版)
- SQL Server與JSP動態網站開發
- 小程序,巧應用:微信小程序開發實戰(第2版)