Machine Learning. Bayesian Learning.

Similar documents
Bayesian Learning. Remark on Conditional Probabilities and Priors. Two Roles for Bayesian Methods. [Read Ch. 6] [Suggested exercises: 6.1, 6.2, 6.

Machine Learning. Bayesian Learning. Acknowledgement Slides courtesy of Martin Riedmiller

Two Roles for Bayesian Methods

BAYESIAN LEARNING. [Read Ch. 6] [Suggested exercises: 6.1, 6.2, 6.6]

CSCE 478/878 Lecture 6: Bayesian Learning

Bayesian Learning. Chapter 6: Bayesian Learning. Bayes Theorem. Roles for Bayesian Methods. CS 536: Machine Learning Littman (Wu, TA)

Stephen Scott.

Bayesian Learning. Bayes Theorem. MAP, MLhypotheses. MAP learners. Minimum description length principle. Bayes optimal classier. Naive Bayes learner

CSCE 478/878 Lecture 6: Bayesian Learning and Graphical Models. Stephen Scott. Introduction. Outline. Bayes Theorem. Formulas

Bayesian Learning Features of Bayesian learning methods:

Lecture 9: Bayesian Learning

Bayesian Learning. Two Roles for Bayesian Methods. Bayes Theorem. Choosing Hypotheses

Notes on Machine Learning for and

Topics. Bayesian Learning. What is Bayesian Learning? Objectives for Bayesian Learning

MODULE -4 BAYEIAN LEARNING

Bayesian Learning. Examples. Conditional Probability. Two Roles for Bayesian Methods. Prior Probability and Random Variables. The Chain Rule P (B)

Decision Trees.

COMP 551 Applied Machine Learning Lecture 5: Generative models for linear classification

Bayesian Learning. CSL603 - Fall 2017 Narayanan C Krishnan

COMP 328: Machine Learning

Decision Trees.

Bayesian Learning. Artificial Intelligence Programming. 15-0: Learning vs. Deduction

Introduction to ML. Two examples of Learners: Naïve Bayesian Classifiers Decision Trees

Bayesian Learning. Bayesian Learning Criteria

Concept Learning.

Introduction to Bayesian Learning. Machine Learning Fall 2018

Uncertainty. Variables. assigns to each sentence numerical degree of belief between 0 and 1. uncertainty

Bayesian Learning Extension

Probability Based Learning

The Naïve Bayes Classifier. Machine Learning Fall 2017

Version Spaces.

Co-training and Learning with Noise

Naïve Bayes classification

Bayesian Learning. Reading: Tom Mitchell, Generative and discriminative classifiers: Naive Bayes and logistic regression, Sections 1-2.

Machine Learning (CS 567)

Bayesian Classification. Bayesian Classification: Why?

Relationship between Least Squares Approximation and Maximum Likelihood Hypotheses

Bayesian Learning (II)

Naïve Bayes classification. p ij 11/15/16. Probability theory. Probability theory. Probability theory. X P (X = x i )=1 i. Marginal Probability

Outline. Training Examples for EnjoySport. 2 lecture slides for textbook Machine Learning, c Tom M. Mitchell, McGraw Hill, 1997

Mining Classification Knowledge

[read Chapter 2] [suggested exercises 2.2, 2.3, 2.4, 2.6] General-to-specific ordering over hypotheses

Mining Classification Knowledge

Algorithms for Classification: The Basic Methods

Lecture 3: Decision Trees

Classification CE-717: Machine Learning Sharif University of Technology. M. Soleymani Fall 2012

9/12/17. Types of learning. Modeling data. Supervised learning: Classification. Supervised learning: Regression. Unsupervised learning: Clustering

Decision-Tree Learning. Chapter 3: Decision Tree Learning. Classification Learning. Decision Tree for PlayTennis

Lecture 24: Other (Non-linear) Classifiers: Decision Tree Learning, Boosting, and Support Vector Classification Instructor: Prof. Ganesh Ramakrishnan

Lecture 3: Decision Trees

Introduction to Machine Learning

Probability Theory. Prof. Dr. Martin Riedmiller AG Maschinelles Lernen Albert-Ludwigs-Universität Freiburg.

Concept Learning through General-to-Specific Ordering

Introduction to Machine Learning

Chapter 3: Decision Tree Learning

Supervised Learning: Regression & Classifiers. Fall 2010

Introduction. Decision Tree Learning. Outline. Decision Tree 9/7/2017. Decision Tree Definition

Confusion matrix. a = true positives b = false negatives c = false positives d = true negatives 1. F-measure combines Recall and Precision:

Algorithmisches Lernen/Machine Learning

Supervised Learning! Algorithm Implementations! Inferring Rudimentary Rules and Decision Trees!

Classification. Classification. What is classification. Simple methods for classification. Classification by decision tree induction

Question of the Day. Machine Learning 2D1431. Decision Tree for PlayTennis. Outline. Lecture 4: Decision Tree Learning

Administration. Chapter 3: Decision Tree Learning (part 2) Measuring Entropy. Entropy Function

Decision Tree Learning Mitchell, Chapter 3. CptS 570 Machine Learning School of EECS Washington State University

CS6220: DATA MINING TECHNIQUES

Machine Learning: Probability Theory

Boosting. Acknowledgment Slides are based on tutorials from Robert Schapire and Gunnar Raetsch

Data Mining Part 4. Prediction

Decision Tree Learning

Applied Logic. Lecture 4 part 2 Bayesian inductive reasoning. Marcin Szczuka. Institute of Informatics, The University of Warsaw

Bayes Rule. CS789: Machine Learning and Neural Network Bayesian learning. A Side Note on Probability. What will we learn in this lecture?

Learning Decision Trees

Learning Decision Trees

Midterm Review CS 7301: Advanced Machine Learning. Vibhav Gogate The University of Texas at Dallas

Decision Trees. Tirgul 5

Midterm Review CS 6375: Machine Learning. Vibhav Gogate The University of Texas at Dallas

Decision Trees. Data Science: Jordan Boyd-Graber University of Maryland MARCH 11, Data Science: Jordan Boyd-Graber UMD Decision Trees 1 / 1

Decision Tree Learning and Inductive Inference

Probabilistic classification CE-717: Machine Learning Sharif University of Technology. M. Soleymani Fall 2016

Universität Potsdam Institut für Informatik Lehrstuhl Maschinelles Lernen. Bayesian Learning. Tobias Scheffer, Niels Landwehr

Decision Tree Learning

Statistical learning. Chapter 20, Sections 1 4 1

CS 6375 Machine Learning

Learning with Probabilities

CMPT Machine Learning. Bayesian Learning Lecture Scribe for Week 4 Jan 30th & Feb 4th

Naïve Bayes Classifiers

Bayesian Methods: Naïve Bayes

Machine Learning: Exercise Sheet 2

CS6375: Machine Learning Gautam Kunapuli. Decision Trees

Machine Learning. Lecture 4: Regularization and Bayesian Statistics. Feng Li.

Statistical learning. Chapter 20, Sections 1 3 1

Lecture : Probabilistic Machine Learning

Logistic Regression. Jia-Bin Huang. Virginia Tech Spring 2019 ECE-5424G / CS-5824

DECISION TREE LEARNING. [read Chapter 3] [recommended exercises 3.1, 3.4]

Universität Potsdam Institut für Informatik Lehrstuhl Maschinelles Lernen. Intelligent Data Analysis. Decision Trees

CS 446 Machine Learning Fall 2016 Nov 01, Bayesian Learning

LINEAR CLASSIFICATION, PERCEPTRON, LOGISTIC REGRESSION, SVC, NAÏVE BAYES. Supervised Learning

Ruslan Salakhutdinov Joint work with Geoff Hinton. University of Toronto, Machine Learning Group

Decision Tree Learning

An Introduction to Statistical and Probabilistic Linear Models

Transcription:

Machine Learning Bayesian Learning Prof. Dr. Martin Riedmiller AG Maschinelles Lernen und Natürlichsprachliche Systeme Institut für Informatik Technische Fakultät Albert-Ludwigs-Universität Freiburg Martin.Riedmiller@uos.de Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 1

Bayesian Learning [Read Ch. 6] [Suggested exercises: 6.1, 6.2, 6.6] Bayes Theorem MAP, ML hypotheses MAP learners Minimum description length principle Bayes optimal classifier Naive Bayes learner Example: Learning over text data Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 2

Two Roles for Bayesian Methods Provides practical learning algorithms Naive Bayes learning Bayesian belief network learning Combine prior knowledge (prior probabilities) with observed data Requires prior probabilities Provides useful conceptual framework Provides gold standard for evaluating other learning algorithms Additional insight into Occam s razor Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 3

Remark on Conditional Probabilities and Priors P((d 1,..., d m ) h): probability that a hypothesis h generated a certain classification for a fixed input data set (x 1,...,x m ) P((x 1,...,x m ) µ, σ 2 ) probability that input data set was generated by a Gaussian distribution with specific parameter values µ, σ = Likelihood of these values Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 4

Remark on Conditional Probabilities and Priors P((d 1,..., d m ) h): probability that a hypothesis h generated a certain classification for a fixed input data set (x 1,...,x m ) P((x 1,...,x m ) µ, σ 2 ) probability that input data set was generated by a Gaussian distribution with specific parameter values µ, σ = Likelihood of these values For a hypothesis h (e.g., a decision tree) P(h) should be seen as prior knowledge about hypothesis: For instance: smaller trees are more probable than more complex trees Or: uniform distribution, if no prior knowledge subjective probability probability as belief Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 4

Bayes Theorem In the following: fixed training set x 1,...,x m Classifications D = (d 1,..., d m ) This allows to determine the most probable hypothesis given the data using Bayes theorem P(h D) = P(D h)p(h) P(D) P(h) = prior probability of hypothesis h P(D) = prior probability of D P(h D) = probability of h given D P(D h) = probability of D given h Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 5

Choosing Hypotheses P(h D) = P(D h)p(h) P(D) Generally want the most probable hypothesis given the training data Maximum a posteriori hypothesis h MAP : h MAP = arg max h H P(h D) = arg max h H P(D h)p(h) P(D) = arg max h H P(D h)p(h) Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 6

Choosing Hypotheses P(h D) = P(D h)p(h) P(D) Generally want the most probable hypothesis given the training data Maximum a posteriori hypothesis h MAP : h MAP = arg max h H P(h D) = arg max h H P(D h)p(h) P(D) = arg max h H P(D h)p(h) If assume P(h i ) = P(h j ) then can further simplify, and choose the Maximum likelihood (ML) hypothesis h ML = arg max h i H P(D h i) Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 6

Does patient have cancer or not? Bayes Theorem A patient takes a lab test and the result comes back positive. The test returns a correct positive result in only 98% of the cases in which the disease is actually present, and a correct negative result in only 97% of the cases in which the disease is not present. Furthermore,.008 of the entire population have this cancer. P(cancer) = P( cancer) = P(+ cancer) = P( cancer) = P(+ cancer) = P( cancer) = Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 7

Basic Formulas for Probabilities Product Rule: probability P(A B) of a conjunction of two events A and B: P(A B) = P(A B)P(B) = P(B A)P(A) Sum Rule: probability of a disjunction of two events A and B: P(A B) = P(A) + P(B) P(A B) Theorem of total probability: if events A 1,..., A n are mutually exclusive with n i=1 P(A i) = 1, then P(B) = n P(B A i )P(A i ) i=1 Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 8

Brute Force MAP Hypothesis Learner 1. For each hypothesis h in H, calculate the posterior probability P(h D) = P(D h)p(h) P(D) 2. Output the hypothesis h MAP with the highest posterior probability h MAP = argmax h H P(h D) Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 9

Relation to Concept Learning Consider our usual concept learning task instance space X, hypothesis space H, training examples D consider the FindS learning algorithm (outputs most specific hypothesis from the version space V S H,D ) What would Bayes rule produce as the MAP hypothesis? Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 10

Relation to Concept Learning Assume fixed set of instances x 1,..., x m Assume D is the set of classifications D = c(x 1 ),..., c(x m ) = d 1,..., d m Choose P(D h): Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 11

Relation to Concept Learning Assume fixed set of instances x 1,..., x m Assume D is the set of classifications D = c(x 1 ),..., c(x m ) Choose P(D h) P(D h) = 1 if h consistent with D P(D h) = 0 otherwise Choose P(h) to be uniform distribution P(h) = 1 H Then, for all h in H P(h D) = 1 V S H,D if h is consistent with D 0 otherwise Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 12

Evolution of Posterior Probabilities P( h ) P(h D1) P(h D1, D2) hypotheses hypotheses hypotheses ( a) ( b) ( c) Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 13

Characterizing Learning Algorithms by Equivalent MAP Learners Inductive system Training examples D Hypothesis space H Candidate Elimination Algorithm Output hypotheses Equivalent Bayesian inference system Training examples D Hypothesis space H P(h) uniform P(D h) = 0 if inconsistent, = 1 if consistent Brute force MAP learner Output hypotheses Prior assumptions made explicit Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 14

Characterizing Learning Algorithms by Equivalent MAP Learners Inductive system Training examples D Hypothesis space H Candidate Elimination Algorithm Output hypotheses Equivalent Bayesian inference system Training examples D Hypothesis space H P(h) uniform P(D h) = 0 if inconsistent, = 1 if consistent Brute force MAP learner Output hypotheses Prior assumptions made explicit Does FindS output a MAP hypothesis?? Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 14

Learning A Real Valued Function y f e h ML Consider any real-valued target function f Training examples x i, d i, where d i is noisy training value: d i = f(x i ) + e i and e i is random variable (noise) drawn independently for each x i according to some Gaussian distribution with mean=0 x Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 15

Learning A Real Valued Function y f e h ML Consider any real-valued target function f Training examples x i, d i, where d i is noisy training value: d i = f(x i ) + e i and e i is random variable (noise) drawn independently for each x i according to some Gaussian distribution with mean=0 Then, the maximum likelihood hypothesis h ML is the one that minimizes the sum of squared errors: x h ML = arg min h H m (d i h(x i )) 2 i=1 Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 15

Learning A Real Valued Function (cont d) Proof: h ML = argmax h H = argmax h H = argmax h H p(d h) m p(d i h) i=1 m i=1 1 2πσ 2 e 1 2 (d i h(x i ) σ ) 2 Maximize logarithm of this instead... h ML = argmax h H ln( m i=1 1 2πσ 2 e 1 2 (d i h(x i ) σ ) 2 ) Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 16

h ML = argmax h H = argmax h H = argmax h H = argmax h H = argmin h H ln( m i=1 m ln i=1 i=1 1 2πσ 2 e 1 2 (d i h(x i ) σ ) 2 ) 1 2πσ 2 1 2 m 1 ( di h(x i ) 2 σ m (d i h(x i )) 2 i=1 m (d i h(x i )) 2 i=1 ( di h(x i ) ) 2 σ ) 2 Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 17

Learning to Predict Probabilities Training examples x i, d i, where d i is 1 or 0 Want to train neural network to output a probability given x i (not only a 0 or 1) example: predicting probability that (insert your favourite soccer team here) wins. Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 18

Learning to Predict Probabilities Training examples x i, d i, where d i is 1 or 0 Want to train neural network to output a probability given x i (not only a 0 or 1) example: predicting probability that (insert your favourite soccer team here) wins. In this case we can show that h ML = argmax h H m d i lnh(x i ) + (1 d i )ln(1 h(x i )) i=1 In other words: use the modified errorfunction, it will do the job. Fits nicely to Multi-layer perceptrons: Weight update rule for a sigmoid unit: w jk w jk + w jk Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 18

where w jk = η m (d i h(x i )) x ijk i=1 Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 19

Minimum Description Length Principle Occam s razor: prefer the shortest hypothesis MDL: prefer the hypothesis h that minimizes h MDL = argmin h H L C1 (h) + L C2 (D h) where L C (x) is the description length of x under encoding C Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 20

Example: H = decision trees, D = training data labels L C1 (h) is # bits to describe tree h L C2 (D h) is # bits to describe D given h Note L C2 (D h) = 0 if examples classified perfectly by h. Need only describe exceptions Hence h MDL trades off tree size for training errors Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 21

Minimum Description Length Principle h MAP = arg max h H P(D h)p(h) = arg max h H log 2 P(D h) + log 2 P(h) = arg min h H log 2 P(D h) log 2 P(h) (1) Interesting fact from information theory: The optimal (shortest expected coding length) code for an event with probability p is log 2 p bits. Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 22

Minimum Description Length Principle h MAP = arg max h H P(D h)p(h) = arg max h H log 2 P(D h) + log 2 P(h) = arg min h H log 2 P(D h) log 2 P(h) (1) Interesting fact from information theory: The optimal (shortest expected coding length) code for an event with probability p is log 2 p bits. So interpret (1): log 2 P(h) is length of h under optimal code log 2 P(D h) is length of D given h under optimal code Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 22

Minimum Description Length Principle h MAP = arg max h H P(D h)p(h) = arg max h H log 2 P(D h) + log 2 P(h) = arg min h H log 2 P(D h) log 2 P(h) (1) Interesting fact from information theory: The optimal (shortest expected coding length) code for an event with probability p is log 2 p bits. So interpret (1): log 2 P(h) is length of h under optimal code log 2 P(D h) is length of D given h under optimal code prefer the hypothesis that minimizes length(h) + length(misclassif ications) Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 22

Most Probable Classification of New Instances So far we ve sought the most probable hypothesis given the data D (i.e., h MAP ) Given new instance x, what is its most probable classification? h MAP (x) is not the most probable classification! Consider: Three possible hypotheses: P(h 1 D) =.4, P(h 2 D) =.3, P(h 3 D) =.3 Given new instance x, h 1 (x) = +, h 2 (x) =, h 3 (x) = What s most probable classification of x? Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 23

Bayes Optimal Classifier Bayes optimal classification: arg max v j V h i H P(v j h i )P(h i D) Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 24

Bayes Optimal Classifier Bayes optimal classification: Example: arg max v j V h i H P(v j h i )P(h i D) P(h 1 D) =.4, P( h 1 ) = 0, P(+ h 1 ) = 1 P(h 2 D) =.3, P( h 2 ) = 1, P(+ h 2 ) = 0 P(h 3 D) =.3, P( h 3 ) = 1, P(+ h 3 ) = 0 Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 24

Bayes optimal classification: Example: Bayes Optimal Classifier arg max v j V h i H P(v j h i )P(h i D) P(h 1 D) =.4, P( h 1 ) = 0, P(+ h 1 ) = 1 P(h 2 D) =.3, P( h 2 ) = 1, P(+ h 2 ) = 0 P(h 3 D) =.3, P( h 3 ) = 1, P(+ h 3 ) = 0 therefore h i H h i H P(+ h i )P(h i D) =.4 P( h i )P(h i D) =.6 Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 24

and arg max v j V h i H P(v j h i )P(h i D) = Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 25

Gibbs Classifier Bayes optimal classifier provides best result, but can be expensive if many hypotheses. Gibbs algorithm: 1. Choose one hypothesis at random, according to P(h D) 2. Use this to classify new instance Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 26

Gibbs Classifier Bayes optimal classifier provides best result, but can be expensive if many hypotheses. Gibbs algorithm: 1. Choose one hypothesis at random, according to P(h D) 2. Use this to classify new instance Surprising fact: Assume target concepts are drawn at random from H according to priors on H. Then (Haussler et al, 1994): E[error Gibbs ] 2E[error BayesOptimal ] Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 26

Gibbs Classifier Bayes optimal classifier provides best result, but can be expensive if many hypotheses. Gibbs algorithm: 1. Choose one hypothesis at random, according to P(h D) 2. Use this to classify new instance Surprising fact: Assume target concepts are drawn at random from H according to priors on H. Then (Haussler et al, 1994): E[error Gibbs ] 2E[error BayesOptimal ] Suppose correct, uniform prior distribution over H, then Pick any hypothesis from VS, with uniform probability Its expected error no worse than twice Bayes optimal Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 26

Naive Bayes Classifier Along with decision trees, neural networks, nearest nbr, one of the most practical learning methods. When to use Moderate or large training set available Attributes that describe instances are conditionally independent given classification Successful applications: Diagnosis Classifying text documents Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 27

Naive Bayes Classifier Assume target function f : X V, where each instance x described by attributes a 1, a 2... a n. Most probable value of f(x) is: v MAP v MAP = argmax v j V = argmax v j V = argmax v j V P(v j a 1, a 2... a n ) P(a 1, a 2... a n v j )P(v j ) P(a 1, a 2... a n ) P(a 1, a 2... a n v j )P(v j ) Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 28

Naive Bayes assumption: P(a 1, a 2... a n v j ) = i P(a i v j ) which gives Naive Bayes classifier: v NB = argmax v j V P(v j ) i P(a i v j ) Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 29

Naive Bayes Learn(examples) For each target value v j Naive Bayes Algorithm ˆP(v j ) estimate P(v j ) For each attribute value a i of each attribute a ˆP(a i v j ) estimate P(a i v j ) Classify New Instance(x) v NB = argmax v j V ˆP(v j ) ai x ˆP(a i v j ) Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 30

Naive Bayes: Example Day Outlook Temperature Humidity Wind PlayTennis D1 Sunny Hot High Weak No D2 Sunny Hot High Strong No D3 Overcast Hot High Weak Yes D4 Rain Mild High Weak Yes D5 Rain Cool Normal Weak Yes D6 Rain Cool Normal Strong No D7 Overcast Cool Normal Strong Yes D8 Sunny Mild High Weak No D9 Sunny Cool Normal Weak Yes D10 Rain Mild Normal Weak Yes D11 Sunny Mild Normal Strong Yes D12 Overcast Mild High Strong Yes D13 Overcast Hot Normal Weak Yes D14 Rain Mild High Strong No Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 31

Naive Bayes: Example Consider PlayTennis again, and new instance Outlk = sun, Temp = cool, Humid = high, Wind = strong Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 32

Naive Bayes: Example Consider PlayTennis again, and new instance Outlk = sun, Temp = cool, Humid = high, Wind = strong Want to compute: v NB = argmax v j V P(v j ) i P(a i v j ) Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 32

Naive Bayes: Example Consider PlayTennis again, and new instance Outlk = sun, Temp = cool, Humid = high, Wind = strong Want to compute: v NB = argmax v j V P(v j ) i P(a i v j ) P(y) P(sun y) P(cool y) P(high y) P(strong y) =.005 P(n) P(sun n) P(cool n) P(high n) P(strong n) =.021 v NB = n Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 32

Naive Bayes: Subtleties 1. Conditional independence assumption is often violated P(a 1, a 2... a n v j ) = i P(a i v j )...but it works surprisingly well anyway. Note don t need estimated posteriors ˆP(v j x) to be correct; need only that argmax v j V ˆP(v j ) i ˆP(a i v j ) = argmax v j V P(v j )P(a 1..., a n v j ) see [Domingos & Pazzani, 1996] for analysis Naive Bayes posteriors often unrealistically close to 1 or 0 Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 33

Naive Bayes: Subtleties 2. what if none of the training instances with target value v j have attribute value a i? Then ˆP(a i v j ) = 0, and... ˆP(v j ) i ˆP(a i v j ) = 0 Typical solution is Bayesian estimate for ˆP(a i v j ) where ˆP(a i v j ) n c + mp n + m n is number of training examples for which v = v j, n c number of examples for which v = v j and a = a i p is prior estimate for ˆP(a i v j ) m is weight given to prior (i.e. number of virtual examples) Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 34

Learning to Classify Text Why? Learn which news articles are of interest Learn to classify web pages by topic Naive Bayes is among most effective algorithms What attributes shall we use to represent text documents?? Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 35

Learning to Classify Text Target concept Interesting? : Document {+, } 1. Represent each document by vector of words one attribute per word position in document 2. Learning: Use training examples to estimate P(+) P( ) P(doc +) P(doc ) Naive Bayes conditional independence assumption P(doc v j ) = length(doc) i=1 P(a i = w k v j ) where P(a i = w k v j ) is probability that word in position i is w k, given v j one more assumption: P(a i = w k v j ) = P(a m = w k v j ), i,m Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 36

Learn naive Bayes text(examples, V ) 1. collect all words and other tokens that occur in Examples V ocabulary all distinct words and other tokens in Examples 2. calculate the required P(v j ) and P(w k v j ) probability terms For each target value v j in V do docs j subset of Examples for which the target value is v j P(v j ) docs j Examples Text j a single document created by concatenating all members of docs j n total number of words in Text j (counting duplicate words multiple times) for each word w k in V ocabulary n k number of times word w k occurs in Text j P(w k v j ) n k +1 n+ V ocabulary Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 37

Classify naive Bayes text(doc) positions all word positions in Doc that contain tokens found in V ocabulary Return v NB, where v NB = argmax v j V P(v j ) i positions P(a i v j ) Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 38

Twenty NewsGroups Given 1000 training documents from each group Learn to classify new documents according to which newsgroup it came from comp.graphics comp.os.ms-windows.misc comp.sys.ibm.pc.hardware comp.sys.mac.hardware comp.windows.x alt.atheism soc.religion.christian talk.religion.misc talk.politics.mideast talk.politics.misc talk.politics.guns Naive Bayes: 89% classification accuracy Random guessing: 5% misc.forsale rec.autos rec.motorcycles rec.sport.baseball rec.sport.hockey sci.space sci.crypt sci.electronics sci.med Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 39

Article from rec.sport.hockey Path: cantaloupe.srv.cs.cmu.edu!das-news.harvard.edu!ogicse!uwm.edu From: xxx@yyy.zzz.edu (John Doe) Subject: Re: This year s biggest and worst (opinion)... Date: 5 Apr 93 09:53:39 GMT I can only comment on the Kings, but the most obvious candidate for pleasant surprise is Alex Zhitnik. He came highly touted as a defensive defenseman, but he s clearly much more than that. Great skater and hard shot (though wish he were more accurate). In fact, he pretty much allowed the Kings to trade away that huge defensive liability Paul Coffey. Kelly Hrudey is only the biggest disappointment if you thought he was any good to begin with. But, at best, he s only a mediocre goaltender. A better choice would be Tomas Sandstrom, though not through any fault of his own, but because some thugs in Toronto decided Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 40

Learning Curve for 20 Newsgroups 100 90 80 70 60 50 40 30 20 10 0 20News Bayes TFIDF PRTFIDF 100 1000 10000 Accuracy vs. Training set size (1/3 withheld for test) Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 41

Summary Probability theory offers a powerful framework to design and analyse learning methods probabilistic analysis offers insight in learning algorithms even if not directly manipulating probabilities, algorithms might be seen fruitfully in a probabilistic perspective Martin Riedmiller, Albert-Ludwigs-Universität Freiburg, Martin.Riedmiller@uos.de Machine Learning 42