Skip to content

Latest commit

 

History

History
73 lines (42 loc) · 2.2 KB

README.md

File metadata and controls

73 lines (42 loc) · 2.2 KB

Bayesian Linear Regression

Sample program to model the data by (normal) linear regression and Bayesian lineaer regression. And show the graph to compare those two.

Environment

  • Python 2.7.6
  • Numpy
  • Matplotlib

Run

$ python bayesian_lr.py

Graph

  • Green: Normal linear regression
  • Blue: Bayesian linear regression

Graph

Logic

The function is as following in general :

Graph

Use the "Gaussian distribution" as the basis function.

Graph

Assuming s = 0.1, c_i = [0.0, 0.1, ..., 1.0].

(1) Normal linear regression

These "omega" can be solved by this equation.

Graph

(2) Bayesian linear regression

The posterior distribution is expressed as following.

Graph
Graph
Graph

The posterior distribution is Gaussian distribution, so the most possible value is :

Graph

So, it is possible to figure out the function by calculating Mu_N.

This time, I assume alpha = 0.1, beta = 9.0.

Phi is the matrix as following.

Graph

Numpy

Reference

(in Japanese) http://gihyo.jp/dev/serial/01/machine-learning/0014?page=1