Supervised Learning: Bayesian Learning
Tags: machinelearning, supervisedlearning
Published: 2019-02-16 02:37:05

---
title: "Supervised Learning: Bayesian Learning"
published: true
description: Lets update our priors! Oh wait we have none.
tags: Machine Learning, Supervised Learning
---

*This is the 10th in a series of class notes as I go through the [Georgia Tech/Udacity Machine Learning course](https://www.udacity.com/course/machine-learning--ud262). The class textbook is [Machine Learning by Tom Mitchell](https://www.cs.ubbcluj.ro/~gabis/ml/ml-books/McGrawHill%20-%20Machine%20Learning%20-Tom%20Mitchell.pdf).*

> This chapter is less theoretical than VC Dimensions, but still more focusing on the theoretical basis of what we do in Supervised Learning.

## The Core Question

What we've been trying to do is: learn the best hypothesis that we can, given some data and domain knowledge.

We are going to refine what our notion of "best" is to be "most probable" hypothesis, out of the hypothesis space.

## Bayes Rule

I'll assume you know this ([more info](https://en.wikipedia.org/wiki/Bayes%27_theorem), wonderful [counterintuitive application here](https://www.youtube.com/watch?v=77jH-M2StRM)):

![https://cdn-images-1.medium.com/max/1600/1*LB-G6WBuswEfpg20FMighA.png](https://cdn-images-1.medium.com/max/1600/1*LB-G6WBuswEfpg20FMighA.png)

Applied to ML:

- A is our hypothesis
- B is our Data
- our hypothesis given the data is `P(A|B)`, what we want to maximize
- our data sampling is `P(B)`
- our prior domain knowledge is represented by `P(A)`
- our updating (the running of the algorithm) is `P(B|A)`, also considered accuracy

Since `P(B)` is constant among hypotheses and we just care about maximizing `P(A|B)`, we can effectively ignore it.

We've had many ways of representing domain knowledge so far - SVM kernels, choosing to use kNN (closer is more similar) - `P(A)` is a more general form of this.

**Maximum Likelihood**: In fact if we further assume we have no priors (aka assume a uniform distribution for `P(A)`), `P(A)` can effectively be ignored. This means maximizing `P(A|B)` (our most likely hypothesis given data) is the same as maximizing `P(B|A)` (the most likely data labels we see given our hypothesis) if we don't have a strong prior. This is the philosophical justification for making projections based on data, but as you can see, even a little bit of domain knowledge will skew/improve our conclusions dramatically.

However, it is impractical to iterate through all hypotheses and mechanically update priors like this. What we are aiming for with Bayes is more of an intuition about the levers we can pull rather than an actual applicable formula.

## The Relationship of Bayes and Version Spaces

**No Noise**: [This proof](https://www.youtube.com/watch?v=ycjPR-C07yM) is too mundane to write out, but basically given no priors, it is a truism that the probability of any particular hypothesis given data (`P(h|D)`) is exactly equal to `1/|VS|` (VS for version space). AKA if all hypotheses are equally likely to be true, then the probability of any one hypothesis being true is 1 / the number of hypotheses. Not exactly exciting stuff, but it derives from Bayes.

**With Noise**: If we assume that noise has a normal distribution, we then use [this proof](https://www.youtube.com/watch?v=F1wRTC9vcDU) to arrive at the sum of squares best fit formula:

![https://qph.fs.quoracdn.net/main-qimg-ebbed10139d890ebc9f5e2c55cc0ab04](https://qph.fs.quoracdn.net/main-qimg-ebbed10139d890ebc9f5e2c55cc0ab04)

## The Minimum Description Objective

By adding a logarithm (a monotonic function, so it doesnt change the end result), we can translate, decompose, and flip the maximization goal we defined above to a minimization with tradeoffs:

![https://wikimedia.org/api/rest_v1/media/math/render/svg/ee09398b5087ee5624cff6bcb57127ed384e95d3](https://wikimedia.org/api/rest_v1/media/math/render/svg/ee09398b5087ee5624cff6bcb57127ed384e95d3)

Here `L` stands for Length, for example the length of a decision tree, which indicates the complexity of the model/hypothesis. `L(h)` is the complexity of the model we have selected, while `L(D|h)` is the data that doesn't fit the model we have selected, aka the error. We want to minimize this total "description length", aka seek the [minimum description length](https://en.wikipedia.org/wiki/Minimum_description_length). This is a very nice mathematical expression of [Occam's razor](https://en.wikipedia.org/wiki/Occam%27s_razor) with a penalty for oversimplification.

There are practical issues with applying this, for example the unit comparability of errors vs model complexity, but you can decide on a rule for trading them off.

## The Big Misdirection

Despite everything we laid out here and in prior chapters, **we don't -really- care about finding the single best or most likely hypothesis**. We care about finding the single most likely **label**. A correct hypothesis will help us get there every time, sure, but if every remaining hypothesis in our version spaces in aggregate point towards a particular label, then that is the one we actually want. 

Thus, Bayesian Learning is merely a stepping stone towards Bayesian Classification, and building a [Bayes Optimal Classifier](https://svivek.com/teaching/machine-learning/fall2018/slides/prob-learning/bayes-optimal-classifier.pdf).

We will explore this in the next chapter on Bayesian Inference.

## Next in our series

Further notes on this topic:

- [a nice introduction to Bayesian Learning with more detail](https://wso2.com/blog/research/part-one-introduction-to-bayesian-learning)
- [application to neural networks, aka Bayesian Networks](http://www.cs.cmu.edu/afs/cs/project/theo-20/www/mlbook/ch6.pdf)
- [great discussion of Bayesian nonparametric learning](http://fastml.com/bayesian-machine-learning/)

Hopefully that was a good introduction to Bayesian Learning. I am planning more primers and would love your feedback and questions on:


- [Overview](https://dev.to/swyx/machine-learning-an-overview-216n)
- Supervised Learning
    - [Decision Trees](https://dev.to/swyx/machine-learning-classification-learning--decision-trees-1mbh)
    - [Regression](https://dev.to/swyx/supervised-learning-regression-4d17)
    - [Neural Networks](https://dev.to/swyx/supervised-learning-neural-networks-mpo)
    - [Instance Based Learning (K Nearest Neighbors)](https://dev.to/swyx/supervised-learning-instance-based-learning-and-k-nearest-neighbors-kge)
    - [Ensemble Learning (AdaBoost)](https://dev.to/swyx/supervised-learning-ensemble-learning-lim)
    - [Kernel Methods & SVMs](https://dev.to/swyx/supervised-learning-support-vector-machines-3mgk)
    - [Computational Learning Theory](https://dev.to/swyx/supervised-learning-computational-learning-theory-160h)
    - [VC Dimensions](https://dev.to/swyx/supervised-learning-vc-dimensions-10b)
    - [Bayesian Learning](https://dev.to/swyx/supervised-learning-bayesian-learning-403l)
    - [Bayesian Inference](https://dev.to/swyx/supervised-learning-bayesian-inference-4l72)
- Unsupervised Learning
    - [Randomized Optimization](https://dev.to/swyx/unsupervised-learning-randomized-optimization-4c1i)
    - [Information Theory](https://dev.to/swyx/unsupervised-learning-information-theory-recap-4iem)
    - Clustering - week of Feb 25
    - Feature Selection - week of Mar 4
    - Feature Transformation - week of Mar 11
- Reinforcement Learning
    - Markov Decision Processes - week of Mar 25
    - "True" RL - week of Apr 1
    - Game Theory - week of Apr 15