Bayesian Theory
We can implement Bayesian probability using Python. For our demo, we generate output values from two independent variables, x1 and x2. The output model is defined as follows:
c is a random value. We define α, β1, β2, and σ as 0.5, 1, 2.5, and 0.5.
These independent variables are generated using a random object from the NumPy
library. After that, we compute the model with these variables.
We can implement this case with the following scripts:
import matplotlib matplotlib.use('Agg') import numpy as np import matplotlib.pyplot as plt # initialization np.random.seed(100) alpha, sigma = 0.5, 0.5 beta = [1, 2.5] size = 100 # Predictor variable X1 = np.random.randn(size) X2 = np.random.randn(size) * 0.37 # Simulate outcome variable Y = alpha + beta[0]*X1 + beta[1]*X2 + np.random.randn(size)*sigma fig, ax = plt.subplots(1, 2, sharex=True, figsize=(10, 4)) fig.subplots_adjust(bottom=0.15, left=0.1) ax[0].scatter(X1, Y) ax[1].scatter(X2, Y) ax[0].set_ylabel('Y') ax[0].set_xlabel('X1...