Docsity
Trusted Seller

Machine Learning Notes Sapienza, Appunti di Machine learning

Toggle sidebar
bg1
Machine Learning Notes
Luca Tomei
Academic Year 2019-2020
Contents
1 Introduction 1
1.1 TargetFunction................................................. 1
1.2 LMSWeightupdaterule............................................ 1
1.3 MachineLearningProblems.......................................... 1
1.3.1 SupervisedLearning .......................................... 1
1.3.2 UnsupervisedLearning......................................... 2
1.3.3 ReinforcementLearning ........................................ 2
1.4 Notation..................................................... 2
2 Classification Evaluation 3
3 Decision Trees 6
3.1 Entropy ..................................................... 7
3.2 InformationGain................................................ 8
3.3 HypothesisSpaceSearchbyID3 ....................................... 9
3.4 IssuesinDecisionTreeLearning ....................................... 9
3.5 OverfittinginDecisionTrees ......................................... 9
3.6 Reduced-ErrorPruning ............................................ 9
3.7 Other algorithms based on Decision Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4 Probability and Bayes Networks 11
4.1 TotalProbabilities ............................................... 12
4.2 ChainRule ................................................... 12
4.3 Independence .................................................. 12
4.4 Conditionalindependence ........................................... 13
4.5 Bayes’Rule ................................................... 13
5 Bayesian Learning 14
5.1 Classification as probabilistic estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.2 MAPandMLHypothesis ........................................... 14
5.3 Brute Force MAP Hypothesis Learner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.4 BayesOptimalClassifier............................................ 15
5.5 NaiveBayesClassifier ............................................. 19
5.6 NaiveBayesAlgorithm............................................. 20
5.7 Learning to Classify Text: Naive Bayes approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
6 Probabilistic models for classification 23
6.1 Probabilistic Generative Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
6.2 MaximumLikelihood.............................................. 24
6.3 Probabilistic Discriminative Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Anteprima parziale del testo

Scarica Machine Learning Notes Sapienza e più Appunti in PDF di Machine learning solo su Docsity!

Machine Learning Notes

Machine Learning Notes

1 Introduction

1 Introduction

1. 1 Target Function

Possible definition of target function V:

  • if b is a final board state that is won, then V(b) = 100
  • if b is a final board state that is lost, then V(b) = − 100
  • if b is a final board state that is drawn, then V(b) = 0
  • if b is not a final state in the game, then V(b) = V(b

′ ), where b

′ is the best final board state that can be achieved

starting from b and playing optimally until the end of the game

1. 2 LMS Weight update rule

In this code c is a small constant used to moderate the rate of learning.

Algorithm 1 LMS Weight update rule

1 : Initialize w i

2 : Do repeatedly:

3 : Select a training example b at random

4 : Compute error(b):

5 : error(b) = Vtr ain(b) −

V(b)

6 : For each board feature fi , update weight wi :

7 : wi ← wi + c · fi · error(b)

1. 3 Machine Learning Problems

General machine learning problem:

  • Learning a function f : X → Y , given a training set D containing sampled information about f
  • Learning a function f means computing an approximated function

f that returns values as close as possible to

f , specially for samples x not present in the training set D

There are 3 main categories for ML problems and what is different in the ML problems categories is how data

is represented.

    1. 1 Supervised Learning

Is a set of problems in which the dataset is formed by a set of pairs input-output (D = {< xi, yi >}), so if I take an

element from X I know the corresponding value in Y.

D ⊂ {(x, y)|x ∈ X, y ∈ Y };

X ≡ A 1 × ... × An, Ai finite sets (Discrete)

X ⊂ R

n (Continuous)

Y ≡ {C 1 , ..., Ck }, (Classification)

Y ⊂ R

k (Regression)

In supervised learning, you train the machine which is well ”labeled”. It means that some data is already tagged

with the correct answer.

In this case we have Classification (aka Pattern Recognition) in which we have the task of learning a function that

has a finite codomain. It returns the class to which a specific instance belong.

Regression is the task of predicting a single output value using training data. We have the task of learning a

function whose domain output is infinite and has the goal to approximate real-valued functions.

Fundamentally, classification is about predicting a label and regression is about predicting a quantity.

Machine Learning Notes

! LucasMac!

2 Classification Evaluation

If any subset of the instances can be represented in a version space and all the solution are computed (search is

completed) then the system is not able to classify new instances. In fact, different hypotheses in a version space may

return different values for a new instance x

′ ! D.

Collecting data is difficult and it’s easy to make some mistakes because data set may contain noisy data and so the

output is different from the true value of the target function. D = {< xi, yi } with yi " c(xi ) for some i. This can be

cause by sensor errors, approximations and human errors and we need statical methods to remove the noise.

2 Classification Evaluation

To introduce the notion of performance metrics in ML we have to define a probability distribution of all the possible

inputs. Consider a typical classification problem:

f : X → Y

D : Probability distribution over X.

S : Sample of n instances drawn from X (according to distribution D) and for which we know f (x)

D is the distribution over the dataset that represent the probability that an element is an element of a class.

Performance Evaluation is based on accuracy and error rate. We can have two definitions of error/accuracy:

  • The True error of hypothesis h with respect to target function f and distribution D is the probability that h

will misclassify an instance according to D:

error D

(h) ≡ Pr

x ∈D

[ f (x) " h(x)]

This error can not be computed because X sometimes is infinite and we don’t know f (x).

  • The Sample error of hypothesis h with respect to target function f and data sample S is the number of

mistakes that h makes on S:

errorS (h) ≡

n

x ∈S

δ( f (x) " h(x))

where δ( f (x) " h(x)) is equal to 1 if f (x) " h(x) and 0 otherwise.

The sample error is the number of mistakes that h makes on a data sample, it can be computed cause for the

samples of S we know the values of the target function. The problem is: this not enough, because we cannot

be sure that this will be the ”resulting error” of the entire distribution. The sample error is computed only on

a small data sample.

accuracy(h) ≡ 1 − error(h)

So, the true error can not be computed (because I don’t have f (x) for each x ∈ X) and the sample error is

computed only on a small data sample. We need to remember that the goal of a learning system is to be accurate

in h(x), ∀x! S and if accuracy S

(h) is very high but accuracy D

(h) is poor our system wold not be very useful.

We call bias the difference between the expected value of the sample error and the true error. Estimator bias:

bias ≡ E[errorS (h)] − erroD (h)

We want to obtain a bias of 0 , with this value in fact we can approximate the true error with the expected

value of the sample error.

  • If S is the training set used to compute h, errorS (h) is optimistically biased.
  • For unbiased estimate h and S must be chosen independently:

E[errorS (h)] = errorD (h)

  • Even with unbiased S errorS (h) may still vary from errorD (h). The smaller the set S, the greater the

expected variance and bigger is S, lower will be the difference between twi errors.

Machine Learning Notes

! LucasMac!

2 Classification Evaluation

Confidence interval: With some probability the true error is in an interval defined by the sample error, where these

2 values are defined by a coefficient zN. If S contains n examples (n ≥ 30 ) drawn independently of h and each other,

with approximately N% probability errorD (h) lies in interval:

errors (h) ± zN

error S

(h)( 1 − error S

(h))

n

where

N% : 50 % 68 % 80 % 90 % 95 % 98 % 99 %

z N

This means that increasing the size of S, n increases and decreases the confidence interval that approaches to error S

In order to compute error S

, we need to:

  • Define T = training set and S = sample space
  • Partition the data set D(D = T ∪ S, T ∩ S = ∅, |T | = 2 / 3 |D|)
  • Compute a hypothesis h using training set T
  • Evaluate error S

(h) =

1

n

x ∈S

δ( f (h) " h(x))

errorS (h) is a random variable and in as unbiased estimator for errorD (h).

Now we want to compare two different hypothesis (d ≡ errorD (h 1 ) − errorD (h 2 )) because we can’t compute the true

difference and we have to estimate it with the sampled difference

d ≡ errorS 1

(h 1 ) − errorS 2

(h 2 ), E[

d] = d

d is an unbiased estimator for d which tell us that i take h 1 if

d is negative, otherwise i choose h 2. Note, you can

use different S 1 and S 2 because they are independent.

Consider error of hypothesis h over

  • training data: errorS (h)
  • entire distribution D of data: errorD (h)

Overfitting

Hypothesis h ∈ H overfits training data if there is an alternative hypothesis h

′ ∈ H that

error S

(h) < error S

(h

′ ) and error D

(h) > error D

(h

′ )

So, in the overfitting we have that the sample error of h is lower than the sample error of h

′ but the true error is

greater, so we have a problem. Taking the best solution which minimize the error on S is not always the best solution

(it may be overfitting). h is the solution of learning algorithm L when using a training set T

h = L(T)

We can evaluate a hypothesis h by estimating the error on different samples S:

  • error S

(h) is the result of only one experiment and the confidence interval can be large.

  • We can perform many experiments and compute error Si

(h) for different independent sample data S i

K-Fold Cross Validation method

  1. Partition data set D into k disjoint sets S 1 , S 2 , ..., Sk (|Si | > 30 )

  2. For i = 1 , ..., k do use Si as test set and the remaining data as training set Ti

  • Ti ← {D − Si }
  • hi ← L(Ti )
  • δ i

← error Si

(h i

  1. Return

errorL,D ≡

k

k "

i= 1

δi

Note: accuracyL,D = 1 − errorL,D.

Repeating the loop k times, I just compute the average of all the errors and I get the best approximation of

the true error. If k is too small, the average will be not good (in general k = 30 is good enough.

Machine Learning Notes

! LucasMac!

3 Decision Trees

3 Decision Trees

The problem we are concentrating on is: ”Given a training set D for a target function c, compute consistent hy-

potheses with respect to D”.

Decision Tree = tree where each node represent a test on attribute and branches assign values to the attribute.

leaves are the result of the classification.

The approach to solve it can be:

  • Define hypothesis space H
  • Implement an algorithm to search h ∈ H that are consistent with D

We are going to considerate an hypotheses space made by the set of decision tree; this means that every hypothesis

is a decision tree.

A decision tree can be transformed in a set of rules, it represents the disjunction of conjunction of all the paths to

the positive (true) leaf nodes. So, if we have for example this decision tree:

we obtain the following rules:

(Outlook = Sunny ∧ Humidit y = Normal) ∨ (Outlook = Overcast) ∨ (Outlook = Rain ∧ Wind = W eak)

In this simple example, internal nodes represent a test of attribute and each brace represent an assignment. So, we

have an ”OR” for each edge from the root and we have an ”AND” for each internal node in the path.

To compute consistent hypothesis we don’t want to compute all the possible ones. There are many decision trees in

the space, maybe with different order of attributes. Given a database, we want to build a tree consistent with it and

which has the best performance.

ID 3 Algorithm

In decision tree learning, ID 3 (Iterative Dichotomiser 3 ) is an algorithm used to generate a decision tree from

a dataset and is typically used in the machine learning and natural language processing domains.

1 ) Create Root node for the tree

2 ) if all Examples are positive, then return the node Root with label +

3 ) if all Examples are negative, then return the node Root with label −

4 ) if Attributes is empty, then return the node Root with label = most common value of T arget attribute

in Examples

5 ) Otherwise:

  • A ← the ”best” decision attribute for Examples
  • Assign A as decision attribute for Root
  • For each value v i

of A

  • add a new branch from Root corresponding to the test A = v i
  • E xamples vi

= subset of E xamples that have value v i

for A

  • if E xamples vi

is empty then add a leaf node with label =

most common value of Target attribute in Examples

  • else

add the tree ID 3 (E xamples vi

, T arget attribute, Attributes − {A})

Machine Learning Notes

! LucasMac!

3 Decision Trees

Explanation of the Algorithm

If we want to create a decision tree from a dataset D, we have to choose as input:

  • Examples: data instances;
  • Target attribute what we want to learn;
  • Attributes: the set that from the domain of the function

As output we want one consistent decision tree, who is built in a recursive way:

  1. In the first step it creates the root node for the tree. Then we can have 3 different steps (all final cases) and a

4 th case that is the recursive case. In first 3 cases the root node would be a leaf that will be labelled with one

possible classification method, the other cases are intermediate, we named after an attribute.

  1. If all Examples are positive (+, true, 1 , ...) then return the Root node with a label +. This means that we will

generate a tree that contains only one leaf node that is labelled with +.

  1. If all Examples are negative (-, false, 0 , ...) then return the Root node with a label −. This means that we will

generate a tree that contains only one leaf node that is labelled with −.

  1. If Attributes is empty, then return the Root node with a label equal to the most common value of Target

attribute in Examples. This will happen cause at some point the recursion will reduce the set of attributes.

If it’s empty, we are going to create a leaf, this is an important feature of decision tree. Neither all examples

are positive neither negative it uses statistics (the most common value), and this happened when we have a

noisy dataset ( =⇒ not consistent hypothesis), algorithm is able to generate a solution even in this case (return

anyway a decision tree).

  1. The fifth point is the recursive case: first we choose the ”best” attribute in Examples, so given the best attribute

we generate all branches associated. Now considering the subset of Examples that contains the branches of

the best attribute. If this subset is empty like before we generate a leaf node with a label equal to the most

common value of Target attribute in Examples. Else we call the recursive algorithm by passing it, the new

subset of Examples and the list of the Attributes without the best attribute used.

If the dataset is consistent, the choice based on most common value will never happen, in fact there will be

never any conflict. This algorithm will produce consistent data set whatever is the choice of the attribute.

We need to choose the best attribute because it will increase the accuracy of the tree. ID 3 select the attribute with

the highest information gain.

Information gain measures how well a given attribute separates the training examples according to their target

classification.

3. 1 Entropy

Entropy is associated to a binary dataset and is nothing but the measure of disorder. Let’s call

  • p⊕ the portion of positive examples in S
  • p⊖ (= 1 − p⊕) the portion of negative examples in S

Entropy measures the impurity of S:

Entropy(S) ≡ −p⊕ log 2

p⊕ − p⊖ log 2

p⊖

So, Entropy is max when the dataset contains exactly half positive and half negative, so when p ⊕

= p ⊖

= 0. 5. The

idea is to reduce entropy partitioning the dataset and going to 0 or to 1.

Machine Learning Notes

! LucasMac!

3 Decision Trees

3. 3 Hypothesis Space Search by ID 3

  • Hypothesis space is complete, it includes for sure the target function;
  • In output we have only one hypothesis consistent with the dataset;
  • No back tracking: when you make a chose you can not turn back. This may limit the performance because in

some case we can find out that later this is not a good choice and you can’t go back;

  • It’s robust to noisy data because it use a statically-based search choices. We use the most common class to

ensure robustness to noisy data and robustness to inconsistencies (also important for improving performance

in terms of accuracy).

  • Uses all training examples at each step. Not good in fact adding a single sample could change the best attribute

and therefore also the whole tree, need to redo again (can change completely).

3. 4 Issues in Decision Tree Learning

  • Determining how deeply to grow the DT
  • Handling continuous attributes
  • Choosing appropriate attribute selection measures
  • Handling training data with missing attribute values
  • Handling attributes with different costs

To consider continuous attributes we use intervals in order to have discrete attributes (to cycle on the passible values).

There are some studies in which info gain is not a good choice, depending for example on the number of values of

the attributes, then we have to use different performance metrics still based on reduction of entropy.

3. 5 Overfitting in Decision Trees

Consider a new data set D

′ = D ∪ d 15

adding a training example:

d 15

=< Sunny, Hot, Normal, Strong, PlayT ennis = No >

ID 3 will generate a different tree T

′

. Note: T is consistent with D and T

′ is consistent with D

′ .

accuracy D

(T

′ ) > accuracy D

(T)

Is not positive that the tree grows over time to ”accommodate” all possible instances because can produce overfitting.

In fact it could happen that even with a better accuracy computed on the dataset used for training we may have

that the accuracy on test dataset decrease.

The accuracy on the training data tends to grow, but the accuracy on the sample outside of the dataset is increased

up to some point (till a size of the tree) then it decreases. The biggest tree is perfectly shaping the training set.

To avoid overfitting we try to do this two things:

  • we stop growing the tree when data is not splitting in a significant way and when I don’t see any improve in

performance, or

  • we build the complete tree and we start cutting some part of the tree to reduce his size (post-prune) because

growing the full tree means that we remove some branches.

To determine the correct tree size:

  • use a separate set of examples (distinct from the training examples) to evaluate the utility of post-pruning. We

use this test set to check if remove that branch lead to an improvement of accuracy.

  • apply a statistical test to estimate accuracy of a tree on the entire data distribution
  • using an explicit measure of the complexity for encoding the examples and the decision trees.

3. 6 Reduced-Error Pruning

I need an approach like cross validation and to understand if the cut would be useful we have to estimate if the cut

will improve the accuracy.

So, before I start the process we partition the dataset in training and, for evaluating the accuracy of the tree,

validation. This is called Reduced-Error Pruning, in which we replace subtrees with the more common values in

order to improve accuracy on the validation set. Repeat until any cut on the tree would decrease the accuracy.

Machine Learning Notes

! LucasMac!

3 Decision Trees

Do until further pruning is harmful (harmful = dannoso) (decreases accuracy):

  1. Remove all the subtree and assign the most common classification

  2. Greedily remove the one that most improves validation set accuracy

Notes:

  • it produces smallest version of most accurate subtree
  • when data set is limited, reducing the set of training examples can give bad results
  • if I cut too much we risk underfitting
  • if we do a different partition in training and validation set, we get a different tree
  • no guarantee to reach global optimal in any case (we start pruning from a tree generated with ID 3 )
  • we’re doing a random cut any time, not the best one =⇒ not guarantee of optimality (the tree generated with

ID 3 is suboptimal, and pruning approach is greedy)

If Attributes have continuous values, we can use intervals in order to have discrete attributes. Else, if we have

attributes with many values or with a cost we can use different performance metrics (not gain) but still based on the

reduction of the entropy. If for some samples we have missing values of an attribute there are statistical methods to

generate a solution without losing the information.

3. 7 Other algorithms based on Decision Trees

  • Random Forest: ensemble method that generates a set of decision trees with some random criteria and integrates

their values into a final result. It is a method that generates a set of decision trees using random criteria (e.g.

random picking attributes) and integrates their values into a final value. The result of the Random Forest is

the most common classification of all the trees (majority vote) and they are less sensitive to overfitting.

  • Random criteria:
  1. random subsets of data (bagging)

  2. random subset of attributes (feature selection)

Machine Learning Notes

! LucasMac!

4 Probability and Bayes Networks

Given these variables we can define propositions: easy for Boolean variable (it itself is a proposition), for discrete

random variable we can use equality constrains, for continuous one equality or inequality. We can combine these

propositions with Boolean operators.

Prior or unconditional probabilities of propositions correspond to belief prior to arrival of any (new) evidence. It’s

the probability of an event with knowing any other information (e.g. (Odd = true) = 0. 5 ).

A probability distribution is the set of probability values for all the possible assignment a random variable (the sum

of all values must be 1 ), for continuous variables the probability distribution is a continuous function.

Joint probability distribution for a set of random variables gives the probability of every atomic joint event on those

random variables (i.e., every sample point in the joint sample space).

Notes:

  • With n variable we get an n-dimensional matrix in which each dimension has the size of the number of possible

values of the variable. This extend also to continuous probabilities distributions (if one of the R v

s is continuous,

also the joint probability distribution is continuous)

  • The sum of all these number must be one. If we can compute a joint probability distribution we have all the

possible information of our process.

I know the outcome of a random variable, how this affect probability of other random variables? Conditional

probability is the probability of an event given another event happened, it specifies how the new information affects

the random variable.

In general, conditional/posterior probabilities are different from joint probabilities and from prior probabilities:

P(Cavit y = true|W eather = sunny) " P(Cavit y = true, W eather = sunny) " P(Cavit y = true)

Conditional probability distributions: representation of all the values of a conditional probabilities of random vari-

ables.

Definition of Conditional Probability:

P(a|b) ≡

P(a ∧ b)

P(b)

if P(b) " 0

product rule P(a ∧ b) = P(a|b)P(b) = P(b|a)P(a)

4. 1 Total Probabilities

For a boolean random variable B:

P(a) = P(a|b)P(b) + P(a|┐b)P(┐b)

In general for a random variable Y accepting mutually exclusive values y i

P(X) =

y i

∈D(Y)

P(X |Y 0 yi )P(Y = yi ), where D(Y ) = set of values for variable Y

4. 2 Chain Rule

Is derived by successive application of product rule:

P(X 1 , X 2 ) = P(X 1 )P(X 2 |X 1 )

P(X 1 , ..., Xn) =

n (

i= 1

P(Xi |X 1 , ..., Xi− 1 )

4. 3 Independence

A and B are independent if and only if:

P(A|B) = P(A) or P(B| A) = P(B) or P(A, B) = P(A)P(B)

Absolute independence powerful, but rare. Complex systems have hundreds of variables, none of which are indepen-

dent.

Machine Learning Notes

! LucasMac!

4 Probability and Bayes Networks

4. 4 Conditional independence

Variables are conditional independent each other when something happens. General formulation: X conditionally

independent from Y given Z iff P(X |Y, Z) = P(X |Z).

P(X, Y |Z) = P(X |Y, Z)P(Y |Z) = P(X |Z)P(Y |Z)

P(Y 1 , ..., Yn |Z) = P(Y 1 |Y 2 , ...Yn, Z)P(Y 2 |Y 3 ...Yn, Z)P(Yn |Z)

Yi conditionally independent from Yj given Z

P(Y

1

, ..., Y

n

|Z) = P(Y

1

|Z)P(Y

2

|Z)P(Y

n

|Z)

Chain rule + Conditional independence:

P(X, Y, Z) = P(X |Y, Z)P(Y, Z) = P(X |Y, Z)P(Y |Z)P(Z) = P(X |Z)P(Y |Z)P(Z)

In most cases, the use of conditional independence reduces the size of the representation of the joint distribution

from exponential in n to linear in n.

4. 5 Bayes’ Rule

Product rule P(a ∧ b) = P(a|b)P(b) = P(b|a)P(a)

=⇒ Bayes’ rule P(a|b) =

P(b|a)P(a)

P(b)

or in distribution form:

P(Y |X) =

P(X |Y )P(Y )

P(X)

= αP(X |Y )P(Y )

Useful for assessing diagnostic probability from causal probability:

P(Cause|E f f ect) =

P(E f f ect|Cause)P(Cause)

P(E f f ect)

Bayes rule: P(Z |Y 1 , ..., Y n

) = αP(Y 1

, ..., Y

n

|Z)P(Z)

Y

i

, ..., Y

n

conditionally independent each other given Z

P(Z |Y

1

, ..., Y

n

) = αP(Y 1

|Z)...P(Y

n

|Z)P(Z)

Effects conditionally independent each other given a cause.

P(Cause|E f f ect 1

, ..., E f f ect n

) = αP(Cause)

i

P(E f f ect i

|Cause)

Total number of parameters is linear in n.

Given a set of random variables we can generate a graph in which random variables are nodes while the edges

represent dependencies. This graph is called Bayesian Network.

Figure 1 : A simple, graphical notation for conditional independence assertions and hence for compact specification

of full joint distributions.

Machine Learning Notes

! LucasMac!

5 Bayesian Learning

If we assume that all the hypotheses have the same probability (P(hi ) = P(hj )) we can simplify and choose the

Maximum likelihood (M L) hypothesis:

hM L = argmax

h ∈H

P(D|h)

To generate a M AP hypothesis we can iterate all over the possible hypotheses and for each of this we can compute

the posteriori probability and we take the hypothesis h M AP

with the highest posteriori probability.

5. 3 Brute Force MAP Hypothesis Learner

Since Bayes theorem provides a principled way to calculate the posterior probability of each hypothesis given the

training data, we can use it as the basis for a straightforward learning algorithm that calculates the probability for

each possible hypothesis, then outputs the most probable. The problem is that we can have infinite hypothesis and

we cannot enumerate all the possibilities. In some case if the space is limited and small it can be computed. So, in

general a learning process can be the brute force:

  1. For each hypothesis h in H, calculate the posterior probability

P(h|D) =

P(D|h)P(h)

P(D)

  1. Output the hypothesis hM AX with the highest posterior probability

h M AP

= argmax

h ∈H

P(h|D) ← Maximum a posteriori

This algorithm may require significant computation, because it applies Bayes theorem to each hypothesis in H to

calculate P(h|D). While this may prove impractical for large hypothesis spaces, the algorithm is still of interest

because it provides a standard against which we may judge the performance of other concept learning algorithms.

Assumptions in order to use Brute Force MAP

  1. The training data D is noise free (i.e., di = c(xi ));

  2. The target concept c is contained in the hypothesis space H;

  3. We have no a priori reason to believe that any hypothesis is more probable than any other.

Given those assumptions the value of P(h) is 1 /|H|.

5. 4 Bayes Optimal Classifier

hM AP : most probable hypothesis given data D but hM AP (x

′ ) may not be the most probable classification cause is

possible that the most probable class has a probability of 0. 4

In general, the most probable classification of the new instance is obtained by combining the predictions of all

hypotheses, weighted by their posterior probabilities.

Consider target function f : X → V, V = {v 1 , ..., vk }, data set D and a new instance x! D:

P(v j

|x, D) =

hi ∈H

P(v j

|x, h i

)P(h i

|D)

total probability over H.

P(vj |x, hi ): probability that hi (x) = vj is independent from DD given hi =⇒ P(vj |x, hi ) = P(vj |x, hi, D), where hi does

not depend on x! D =⇒ P(hi |x, D) = P(hi |D).

Bayes Optimal Classifier

Class of a new instance x:

vOB = argmax

vj ∈V

hi ∈H

P(vj |x, hi )P(hi |D)

This is a method in which the value of the classification of an instance x, given a dataset D, is given by the

argmax of the sum of all possible hypothesis, that is sum the probability that each hypothesis give to that

class for that x

′ weighted with the probability of this hypothesis.

Machine Learning Notes

! LucasMac!

5 Bayesian Learning

Example:

P(h 1

|D) = 0. 4 , P(⊖|x, h 1

) = 0 , P(⊕|x, h 1

P(h 2

|D) = 0. 3 , P(⊖|x, h 2

) = 1 , P(⊕|x, h 2

P(h 3

|D) = 0. 3 , P(⊖|x, h 3

) = 1 , P(⊕|x, h 3

therefore (^) "

hi ∈H

P(⊕|x, hi )P(hi |D) = 0. 4

hi ∈H

P(⊖|x, hi )P(hi |D) = 0. 6 , cause h 2 and h 3 give ⊖ and their probability was 0. 3

and

vOB = argmax

vj ∈V

hi ∈H

P(vj |x, hi )P(hi |D) = ⊖

Any system that classifies new instances according to Bayes optimal equation is called a Bayes optimal classifier, or

Bayes optimal learner. No other classification method using the same hypothesis space and same prior knowledge

can outperform this method on average. This method maximizes the probability that the new instance is classified

correctly, given the available data, hypothesis space, and prior probabilities over the hypotheses.

  • Optimal learner : no other classification method using the same hypothesis space and same prior knowledge

can outperform this method on average. The main problem is that H is big or infinite, so i can not perform

the a posteriori probability.,

  • Very powerful : labeling new instances x with argmax

vj ∈V

P(v j

|x, D) can correspond to none of the hypotheses in H.

We can’t use Optimal Bayes cause we cannot compute it. The idea now is: I can’t solve the real problem, so under

some assumptions the real problem can be simplified and for this simplified problem I can find the solution. When-

ever I apply some assumption to simplify the problem, we have an approximated solution.

Some Distributions

  • Bernoully Distribution: Probability distribution of a binary random variable X ∈ { 0 , 1 }

P(X = 1 ) = θ, P(X = 0 ) = 1 − θ

(e.g. observing head after flipping a coin, extracting a lime candy, ...)

P(X = x; θ) = θ

x ( 1 − θ)

1 −x

  • Multivariate Bernoully Distribution: Joint probability distribution of a set of binary random

variables X 1

, ..., X

n

, each random variable following Bernoully distribution

P(X

1

= k 1

, ..., X

n

= k n

; θ 1

, ...., θ n

), with k i

(e.g. observing head after flipping a coin and extracting a lime candy, ...)

Under assumption that random variables X i

are mutually independent, Multi-variate Bernoulli distri-

bution is the product of n Bernoulli distributions:

n (

i= 1

P(X

i

= k i

; θ i

  • Binomial Distribution: Probability distribution of k outcomes from n Bernoulli trials

P(X = k; n, θ) =

n

k

θ

k ( 1 − θ)

n−k

(e.g., flipping a coint n times and observing k heads, extracting k lime candies after n extractions, ...)

  • Multinomial Distribution: Generalization of binomial distribution for discrete valued random vari-

ables with d possible outcomes. Probability distribution of k 1

outcomes for X 1

, ..., k d

outcomes for X d

after n trials (with

i= 1 ...d

k i

= n)

P(X

1

= k 1

, ..., X

d

= k d

; n, θ 1

, ...., θ d

n!

k 1

!...k n

θ

k 1

1

· ... · θ

k d

d

Machine Learning Notes

! LucasMac!