Baixe o app para aproveitar ainda mais
Prévia do material em texto
APRENDIZAGEM POR CLASSIFICADORES LINEARES Baseado no livro do David Poole Função linear ¨ Uma de recursos X1, … , Xn é uma função da forma: ¨ Inventamos um novo recurso X0 que tem valor 1, para não torná-lo é um caso especial. Linear Function A linear function of features X1, . . . ,Xn is a function of the form: f w (X1, . . . ,Xn) = w0 + w1X1 + · · · + wnXn We invent a new feature X0 which has value 1, to make it not a special case. c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 11 Regressão linear ¨ Na a saída é uma função linear dos recursos de entrada. ¨ A soma de erro quadrados sobre os exemplos E para saída Y é: ¨ Objetivo: encontrar os pesos que minimizam . Linear Regression Linear regression is where the output is a linear function of the input features. pvalw (e,Y ) = w0 + w1val(e,X1) + · · · + wnval(e,Xn) The sum of squares error on examples E for output Y is: ErrorE (w) = X e2E (val(e,Y )� pvalw (e,Y ))2 = X e2E (val(e,Y )�(w0+w1val(e,X1)+· · ·+wnval(e,Xn)))2 Goal: find weights that minimize ErrorE (w). c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 12 Linear Regression Linear regression is where the output is a linear function of the input features. pvalw (e,Y ) = w0 + w1val(e,X1) + · · · + wnval(e,Xn) The sum of squares error on examples E for output Y is: ErrorE (w) = X e2E (val(e,Y )� pvalw (e,Y ))2 = X e2E (val(e,Y )�(w0+w1val(e,X1)+· · ·+wnval(e,Xn)))2 Goal: find weights that minimize ErrorE (w). c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 13 Linear Regression Linear regression is where the output is a linear function of the input features. pvalw (e,Y ) = w0 + w1val(e,X1) + · · · + wnval(e,Xn) The sum of squares error on examples E for output Y is: ErrorE (w) = X e2E (val(e,Y )� pvalw (e,Y ))2 = X e2E (val(e,Y )�(w0+w1val(e,X1)+· · ·+wnval(e,Xn)))2 Goal: find weights that minimize ErrorE (w). c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 12 Regressão linear ¨ Na a saída é uma função linear dos recursos de entrada. ¨ A soma dos erros quadrados sobre os exemplos para saída é: ¨ Objetivo: encontrar os pesos que minimizam . Linear Regression Linear regression is where the output is a linear function of the input features. pvalw (e,Y ) = w0 + w1val(e,X1) + · · · + wnval(e,Xn) The sum of squares error on examples E for output Y is: ErrorE (w) = X e2E (val(e,Y )� pvalw (e,Y ))2 = X e2E (val(e,Y )�(w0+w1val(e,X1)+· · ·+wnval(e,Xn)))2 Goal: find weights that minimize ErrorE (w). c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 12 Linear Regression Linear regression is where the output is a linear function of the input features. pvalw (e,Y ) = w0 + w1val(e,X1) + · · · + wnval(e,Xn) The sum of squares error on examples E for output Y is: ErrorE (w) = X e2E (val(e,Y )� pvalw (e,Y ))2 = X e2E (val(e,Y )�(w0+w1val(e,X1)+· · ·+wnval(e,Xn)))2 Goal: find weights that minimize ErrorE (w). c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 13 Encontrando os pesos que minimizam o . ¨ Encontrar o mínimo analiticamente. Eficaz quando pode ser feito (e.g., para a regressão linear). ¨ Encontre o mínimo iterativamente. Funciona para classes maiores problemas. Descida gradiente: ¨ η é o tamanho de etapa de descida do gradiente, a . Linear Regression Linear regression is where the output is a linear function of the input features. pvalw (e,Y ) = w0 + w1val(e,X1) + · · · + wnval(e,Xn) The sum of squares error on examples E for output Y is: ErrorE (w) = X e2E (val(e,Y )� pvalw (e,Y ))2 = X e2E (val(e,Y )�(w0+w1val(e,X1)+· · ·+wnval(e,Xn)))2 Goal: find weights that minimize ErrorE (w). c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 13 Finding weights that minimize ErrorE (w) Find the minimum analytically. E↵ective when it can be done (e.g., for linear regression). Find the minimum iteratively. Works for larger classes of problems. Gradient descent: wi wi � ⌘@ErrorE (w) @wi ⌘ is the gradient descent step size, the learning rate. c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 15 Linear Regression Linear regression is where the output is a linear function of the input features. pvalw (e,Y ) = w0 + w1val(e,X1) + · · · + wnval(e,Xn) The sum of squares error on examples E for output Y is: ErrorE (w) = X e2E (val(e,Y )� pvalw (e,Y ))2 = X e2E (val(e,Y )�(w0+w1val(e,X1)+· · ·+wnval(e,Xn)))2 Goal: find weights that minimize ErrorE (w). c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 12 Encontrando os pesos que minimizam o . ¨ Encontrar o mínimo analiticamente. Eficaz quando pode ser feito (e.g., para a regressão linear). ¨ Encontrar o mínimo iterativamente. Funciona para classes maiores de problemas. : ¨ η é o tamanho da etapa de descida do gradiente, a . Linear Regression Linear regression is where the output is a linear function of the input features. pvalw (e,Y ) = w0 + w1val(e,X1) + · · · + wnval(e,Xn) The sum of squares error on examples E for output Y is: ErrorE (w) = X e2E (val(e,Y )� pvalw (e,Y ))2 = X e2E (val(e,Y )�(w0+w1val(e,X1)+· · ·+wnval(e,Xn)))2 Goal: find weights that minimize ErrorE (w). c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 13 Finding weights that minimize ErrorE (w) Find the minimum analytically. E↵ective when it can be done (e.g., for linear regression). Find the minimum iteratively. Works for larger classes of problems. Gradient descent: wi wi � ⌘@ErrorE (w) @wi ⌘ is the gradient descent step size, the learning rate. c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 15 Descida de gradiente para Regressão Linear Gradient Descent for Linear Regression 1: procedure LinearLearner(X ,Y ,E , ⌘) 2: Inputs 3: X : set of input features, X = {X1, . . . ,Xn} 4: Y : output feature 5: E : set of examples from which to learn 6: ⌘: learning rate 7: initialize w0, . . . ,wn randomly 8: repeat 9: for each example e in E do 10: � val(e,Y )� pvalw (e,Y ) 11: for each i 2 [0, n] do 12: wi wi + ⌘�val(e,Xi) 13: until some stopping criterion is true 14: return w0, . . . ,wn c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 16 Classificador linear ¨ Suponha que você está fazendo classificação binária, com classes {0,1} (e.g., usando funções indicadoras). ¨ Não é correto fazer uma previsão menor que 0 ou maior que 1. ¨ Usa-se uma do formulário: onde f é uma função de ativação. ¨ Uma simples é a : Linear Classifier Assume we are doing binary classification, with classes {0, 1} (e.g., using indicator functions). There is no point in making a prediction of less than 0 or greater than 1. A squashed linear function is of the form: f w (X1, . . . ,Xn) = f (w0 + w1X1 + · · · + wnXn) where f is an activation function . A simple activation function is the step function: f (x) = ⇢ 1 if x � 0 0 if x < 0 c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 17 Descida de gradiente para classificadores lineares ¨ Se a função de ativação for , podemos usar a descida de gradiente para atualizar os pesos. A soma dos erro quadrados é: ¨ A derivada parcial com respeito ao peso wi é: onde ¨ Assim, cada exemplo atualiza cada peso por GradientDescent for Linear Classifiers If the activation is di↵erentiable, we can use gradient descent to update the weights. The sum of squares error is: ErrorE (w) = X e2E (val(e,Y )� f ( X i wi ⇥ val(e,Xi)))2 The partial derivative with respect to weight wi is: @ErrorE (w) @wi = �2⇥�⇥ f 0( X i wi⇥val(e,Xi))⇥val(e,Xi) where � = val(e,Y )� pvalw (e,Y ). Thus, each example e updates each weight wi by wi wi + ⌘ ⇥ � ⇥ f 0( X i wi ⇥ val(e,Xi))⇥ val(e,Xi) c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 18 Gradient Descent for Linear Classifiers If the activation is di↵erentiable, we can use gradient descent to update the weights. The sum of squares error is: ErrorE (w) = X e2E (val(e,Y )� f ( X i wi ⇥ val(e,Xi)))2 The partial derivative with respect to weight wi is: @ErrorE (w) @wi = �2⇥�⇥ f 0( X i wi⇥val(e,Xi))⇥val(e,Xi) where � = val(e,Y )� pvalw (e,Y ). Thus, each example e updates each weight wi by wi wi + ⌘ ⇥ � ⇥ f 0( X i wi ⇥ val(e,Xi))⇥ val(e,Xi) c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 18 Gradient Descent for Linear Classifiers If the activation is di↵erentiable, we can use gradient descent to update the weights. The sum of squares error is: ErrorE (w) = X e2E (val(e,Y )� f ( X i wi ⇥ val(e,Xi)))2 The partial derivative with respect to weight wi is: @ErrorE (w) @wi = �2⇥�⇥ f 0( X i wi⇥val(e,Xi))⇥val(e,Xi) where � = val(e,Y )� pvalw (e,Y ). Thus, each example e updates each weight wi by wi wi + ⌘ ⇥ � ⇥ f 0( X i wi ⇥ val(e,Xi))⇥ val(e,Xi) c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 18 A função de ativação sigmóide ou logística The sigmoid or logistic activation function 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 -10 -5 0 5 10 1 1+ e- x f (x) = 1 1 + e�x f 0(x) = f (x)(1� f (x)) c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 20 The sigmoid or logistic activation function 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 -10 -5 0 5 10 1 1+ e- x f (x) = 1 1 + e�x f 0(x) = f (x)(1� f (x)) c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 20 A função de ativação sigmóide ou logística The sigmoid or logistic activation function 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 -10 -5 0 5 10 1 1+ e- x f (x) = 1 1 + e�x f 0(x) = f (x)(1� f (x)) c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 20 Linearmente separáveis ¨ Uma classificação é se houver um hiperplano onde a classificação é verdade em um lado do hiperplano e falso do outro lado. ¨ Para a função sigmóide, o hiperplano ocorre quando: ¨ Se os dados são linearmente separáveis, o erro pode ser feito arbitrariamente pequeno. Linearly Separable A classification is linearly separable if there is a hyperplane where the classification is true on one side of the hyperplane and false on the other side. For the sigmoid function, the hyperplane is when: w0 + w1 ⇥ val(e,X1) + · · · + wn ⇥ val(e,Xn) = 0. If the data are linearly separable, the error can be made arbitrarily small. + + +- 0 1 0 1 or - + -- 0 1 0 1 and + - +- 0 1 0 1 xor c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 21 Linearly Separable A classification is linearly separable if there is a hyperplane where the classification is true on one side of the hyperplane and false on the other side. For the sigmoid function, the hyperplane is when: w0 + w1 ⇥ val(e,X1) + · · · + wn ⇥ val(e,Xn) = 0. If the data are linearly separable, the error can be made arbitrarily small. + + +- 0 1 0 1 or - + -- 0 1 0 1 and + - +- 0 1 0 1 xor c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 7.3, Page 21 MÉTODOS ESTATÍSTICOS DE APRENDIZAGEM Baseada em: RUSSEL, S.; PETER, N. “Inteligência Artificial” - cap 20. MITCHELL, T. “Machine Learning” – cap. 6 Aprendizado Bayesiano completo ¨ Vê a aprendizagem como uma atualização Bayesiana de uma distribuição de probabilidade no espaço de hipótese. ¨ H é a variável de hipótese com valores h1, h2, ... e distribuição prévia P(H). ¨ A jéssima observação dj apresenta o resultado da variável aleatória Dj para os dados de treinamento d=d1,...,dN ¨ Tendo em conta os dados até agora, cada hipótese tem uma probabilidade a posteriori: P(hi|d) = αP(d|hi)P(hi) na qual P(d|hi) é chamado de ( ) Aprendizado Bayesiano completo ¨ As previsões usam uma sobre as hipóteses: P(X|d) = Σi P(X|d,hi)P(hi|d) = Σi P(X|hi)P(hi|d) ¨ Desta forma, não há necessidade de se escolher uma melhor hipótese! Exemplo ¨ Suponha que existem cinco tipos de sacos de doces: ¤ 10% são : 100% doces de cereja ¤ 20% são : 75% doces de cereja + 25% doces de lima ¤ 40% são : 50% doces de cereja + 50% doces de lima ¤ 20% são : 25% doces de cereja + 75% doces de lima ¤ 10% são : 100% doces de lima ¨ Em seguida, observamos 10 doces retirados de alguns saco: ¨ Que tipo de saco é? De qual sabor será o próximo doce? Example Suppose there are five kinds of bags of candies: 10% are h1: 100% cherry candies 20% are h2: 75% cherry candies + 25% lime candies 40% are h3: 50% cherry candies + 50% lime candies 20% are h4: 25% cherry candies + 75% lime candies 10% are h5: 100% lime candies Then we observe candies drawn from some bag: What kind of bag is it? What flavour will the next candy be? Chapter 20, Sections 1–3 4 Example Suppose there are five kinds of bags of candies: 10% are h1: 100% cherry candies 20% are h2: 75% cherry candies + 25% lime candies 40% are h3: 50% cherry candies + 50% lime candies 20% are h4: 25% cherry candies + 75% lime candies 10% are h5: 100% lime candies Then we observe candies drawn from some bag: What kind of bag is it? What flavour will the next candy be? Chapter 20, Sections 1–3 4 Probabilidade posterior das hipóteses Posterior probability of hypotheses 0 0.2 0.4 0.6 0.8 1 0 2 4 6 8 10 Po ste rio r p ro ba bil ity o f h yp ot he sis Number of samples in d P(h1 | d)P(h2 | d)P(h3 | d)P(h4 | d)P(h5 | d) Chapter 20, Sections 1–3 5 Probabilidade da predição Prediction probability 0.4 0.5 0.6 0.7 0.8 0.9 1 0 2 4 6 8 10 P( ne xt ca nd y i s l im e | d ) Number of samples in d Chapter 20, Sections 1–3 6 Hipótese de Máximo a Posteriori (MAP) ¡ Realizar a somatória ao longo do espaço de hipótese é muitas vezes intratável (e.g., 18.446.744.073.709.551.616 funções booleanas de 6 atributos) ¡ Uma aproximação muito comum para calcular a previsão é fazê-la com base em uma única hipótese mais provável. § Uma hi que maximize P(hi|d) – ou § Escolher hMAP maximizando P(hi|d), i.e., maximize P(d|hi).P(hi) or log P(d|hi) + log P(hi) § As previsões feitas desta forma são aproximadamente bayesianas até o ponto em que P(X|d) é aproximadamente igual a P(X|hMAP). ¨ Para hipóteses determinísticas, P(d|hi) é 1 se consistente, 0 caso contrário ⇒ MAP = hipótese consistente mais simples (cf. ciência) Hipótese de Máximo a Posteriori (MAP) ¡ No exemplo dos doces hMAP = h5 após d1=d2=d3=lima § Neste ponto a P(d4=lima) = 1, enquanto a previsão bayesiana é mais prudente P(d4=lima) = 0,8. § À medida que chegam mais dados as previsões de MAP e Bayes se tornam cada vez mais próximas, porque as concorrentes da hipótese MAP se tornam cada vez menos prováveis.Posterior probability of hypotheses 0 0.2 0.4 0.6 0.8 1 0 2 4 6 8 10 Po ste rio r p ro ba bil ity o f h yp ot he sis Number of samples in d P(h1 | d)P(h2 | d)P(h3 | d)P(h4 | d)P(h5 | d) Chapter 20, Sections 1–3 5 Hipótese de Máximo Grau de Probabilidade (ML) ¨ Supor uma probabilidade a priori sobre o espaço de hipóteses simplifica os cálculos. ¨ A aprendizagem pelo ( ) se reduz à escolha de um hi que maximize P(d|Hi). ¤ i.e. simplesmente obtenha o melhor ajuste aos dados; ¤ idêntico ao MAP para distribuição a priori uniforme (o que é razoável se todas as hipóteses são da mesma complexidade) ¨ ML proporciona uma boa aproximação para a aprendizagem bayesiana e de MAP quando o conjunto de dados é grande. ¨ ML é o método de aprendizagem estatístico “padrão” (não Bayesiano) Modelo de Bayes Ótimo ¨ Dada uma nova instância X, qual é a sua classificação mais provável? cereja ou lima? § Vimos que hMAP(X) nem sempre é a classificação mais provável. ¡ Considere a probabilidade das hipóteses: § P(h1|D) = 0, P(h2|D) = 0.05, P(h3|D) = 0.2, P(h4|D) = 0.35 e P(h5|D) = 0.4 ¡ E as probabilidades de lima dada cada hipótese: § P(lima|h1) = 0, P(lima|h2) = 0,25, P(lima|h3) = 0.5, P(lima|h4) = 0.75 e P(lima|h5) = 1 ¡ Qual é a classificação mais provável de X? lima ou cereja? Modelo de Bayes Ótimo Classificação do próximo doce após os dados abservados D: P(X |D) = P(X | hi i ∑ )P(hi |D) P(l |D) = P(l | h1)P(h1 |D)+P(l | h2 )P(h2 |D)+P(l | h3)P(h3 |D) +P(l | h4 )P(h4 |D)+P(l | h5 )P(h5 |D) = 0,8 P(c |D) = P(c | h1)P(h1 |D)+P(c | h2 )P(h2 |D)+P(c | h3)P(h3 |D) +P(c | h4 )P(h4 |D)+P(c | h5 )P(h5 |D) = 0, 2 Desta forma, a classificação do próximo doce será = lima (0,8 > 0,2) Modelo de Bayes Ótimo Se a possível classificação do novo exemplo pode ser qualquer valor v j ∈ V, a probabilidade de que a classificação correta seja v j : P(vj |D) = P(vj | hi )*P(hi |D) i ∑ e a classificação Bayesiana ótima será: argmax v j∈ V P(vj | hi )*P(hi |D) i ∑ Modelo de Bayes Ingênuo (Naive Bayes) VMAP = argmax vj∈ V P(vj | a1,...,an ) VMAP = argmax vj∈ V P(a1,...,an | vj )*P(vj ) P(a1,...,an ) VMAP = argmax vj∈ V P(a1,...,an | vj )*P(vj ) ¡ Suponha uma função de classificação f: X → V, onde cada instância X é descrita pelos atributos {a1, …, an}. ¡ O valor mais provável de f(x) é: Modelo de Bayes Ingênuo (Naive Bayes) ∏= i jijn vaPvaaP )|()|,...,( 1 ¨ Calcular P(vj) a partir dos dados de treinamento é fácil, o problema é calcular a probabilidade P(a1,..., an | vj). ¨ Suposição Bayesiana Ingênua - as variáveis a1,..., an são independentes : ¡ Classificador Bayesiano Ingênuo: ∏ ∈ ∈ = = i jij V MAP jjn V MAP vaPvPV vPvaaPV )|(*)(argmax )(*)|,...,(argmax j j v 1 v Modelo de Bayes Ingênuo (Naive Bayes) • Dia Tempo Temp. Humid. Vento Jogar • D1 Sol Quente Alta Fraco Não • D2 Sol Quente Alta Forte Não • D3 Coberto Quente Alta Fraco Sim • D4 Chuva Normal Alta Fraco Sim • D5 Chuva Frio Normal Fraco Não • D6 Chuva Frio Normal Forte Não • D7 Coberto Frio Normal Forte Sim • D8 Sol Normal Alta Fraco Não • D9 Sol Frio Normal Fraco Sim • D10 Chuva Normal Normal Fraco Sim • D11 Sol Frio Alta Forte ? P(Sim) = 5/10 = 0.5 P(Não) = 5/10 = 0.5 P(Sol|Sim) = 1/5 = 0.2 P(Sol|Não) = 3/5 = 0.6 P(Frio|Sim) = 2/5 = 0.4 P(Frio|Não) = 2/5 = 0.4 P(Alta|Sim) = 2/5 = 0.4 P(Alta|Não) = 3/5 = 0.6 P(Forte|Sim) = 1/5 = 0.2 P(Forte|Não) = 2/5 = 0.4 P(Sim)*P(Sol|Sim)*P(Frio|Sim)*P(Alta|Sim)* P(Forte|Sim) = 0.0032 P(Não)*P(Sol|Não)*P(Frio|Não)*P(Alta|Não)*P(Forte|Não) = 0.0288 ⇒ Jogar_Tenis (D11) = Não Modelo de Bayes Ingênuo (Naive Bayes) • Dia Tempo Temp. Humid. Vento Jogar • D1 Sol Quente Alta Fraco Não • D2 Sol Quente Alta Forte Não • D3 Coberto Quente Alta Fraco Sim • D4 Chuva Normal Alta Fraco Sim • D5 Chuva Frio Normal Fraco Não • D6 Chuva Frio Normal Forte Não • D7 Coberto Frio Normal Forte Sim • D8 Sol Normal Alta Fraco Não • D9 Sol Frio Normal Fraco Sim • D10 Chuva Normal Normal Fraco Sim • D12 Coberto Normal Normal Forte ? Exercício: Calcule o classificação do exemplo D12 utilizando os 10 exemplos de treinamento acima. Modelo de Bayes Ingênuo (Naive Bayes) )(*)|,...,(argmax 1 vj jjn V vPvaaP ∈ ¨ A suposição de independência condicional é frequentemente violada. ¡ Mas o modelo funciona surpreendentemente bem. ¨ Não é necessário calcular a probabilidade posterior P(vj|X), somente o valor máximo para cada vj . Naive Bayes para classificação de documentos ¡ Classificar documentos em duas classes: § {interesse, não-interesse} ¨ As variáveis a1,...an são palavras de um vocabulário e P(ai|vj) é a frequência com que cada palavra ai aparece entre os documentos da classe vj . ¡ P(vj) = (nº de doc da classe vj)/(nº total de doc) Aprendizagem de parâmetros usando ML nas redes de Bayes ¨ Você recebe um saco de um novo fabricante. Qual a fração θ de doces de cereja? ¨ Qualquer θ é possível, i.e., existe um continuo de hipóteses hθ. ¨ θ é um para essa família simples (binomial) de modelos. ¨ Suponha que nós desembrulhemos doces, de cerejas e = N - c de lima ¨ Estas observações são (independentes e identicamente distribuídas), assim ML parameter learning in Bayes nets Bag from a new manufacturer; fraction θ of cherry candies? Flavor P F=cherry( ) θAny θ is possible: continuum of hypotheses hθ θ is a parameter for this simple (binomial) family of models Suppose we unwrap N candies, c cherries and "=N − c limes These are i.i.d. (independent, identically distributed) observations, so P (d|hθ) = N∏ j=1 P (dj|hθ) = θc · (1− θ)" Maximize this w.r.t. θ—which is easier for the log-likelihood: L(d|hθ) = logP (d|hθ) = N∑ j=1 logP (dj|hθ) = c log θ + " log(1− θ) dL(d|hθ) dθ = c θ − " 1− θ = 0 ⇒ θ = c c + " = c N Seems sensible, but causes problems with 0 counts! Chapter 20, Sections 1–3 9 ML parameter learning in Bayes nets Bag from a new manufacturer; fraction θ of cherry candies? Flavor P F=cherry( ) θAny θ is possible: continuum of hypotheses hθ θ is a parameter for this simple (binomial) family of models Suppose we unwrap N candies, c cherries and "=N − c limes These are i.i.d. (independent, identically distributed) observations, so P (d|hθ) = N∏ j=1 P (dj|hθ) = θc · (1− θ)" Maximize this w.r.t. θ—which is easier for the log-likelihood: L(d|hθ) = logP (d|hθ) = N∑ j=1 logP (dj|hθ) = c log θ + " log(1− θ) dL(d|hθ) dθ = c θ − " 1− θ = 0 ⇒ θ = c c + " = c N Seems sensible, but causes problems with 0 counts! Chapter 20, Sections 1–3 9 Aprendizagem de parâmetros usando ML nas redes de Bayes ¨ Maximizando com respeito a θ— que é mais fácil para o : ¨ Parece sensato, mas causa problemas com contagens em 0 ! ML parameter learning in Bayes nets Bag from a new manufacturer; fraction θ of cherry candies? Flavor P F=cherry( ) θAny θ is possible: continuum of hypotheses hθ θ is a parameter for this simple (binomial) family of models Suppose we unwrapN candies, c cherries and "=N − c limes These are i.i.d. (independent, identically distributed) observations, so P (d|hθ) = N∏ j=1 P (dj|hθ) = θc · (1− θ)" Maximize this w.r.t. θ—which is easier for the log-likelihood: L(d|hθ) = logP (d|hθ) = N∑ j=1 logP (dj|hθ) = c log θ + " log(1− θ) dL(d|hθ) dθ = c θ − " 1− θ = 0 ⇒ θ = c c + " = c N Seems sensible, but causes problems with 0 counts! Chapter 20, Sections 1–3 9 Parâmetros múltiplos ¨ O invólucro vermelho/verde depende do sabor: ¨ O grau de probabilidade para, por exemplo, doce cereja em um invólucro verde: ¨ N doces, rc doces de cereja envoltos em vermelho , etc.: Multiple parameters Red/green wrapper depends probabilistically on flavor: P F=cherry( ) Flavor Wrapper P( )W=red | FF cherry 2lime θ 1θ θ Likelihood for, e.g., cherry candy in green wrapper: P (F = cherry ,W = green |hθ,θ1,θ2) = P (F = cherry |hθ,θ1,θ2)P (W = green |F = cherry , hθ,θ1,θ2) = θ · (1− θ1) N candies, rc red-wrapped cherry candies, etc.: P (d|hθ,θ1,θ2) = θc(1− θ)" · θrc1 (1− θ1)gc · θr!2 (1− θ2)g! L = [c log θ + " log(1− θ)] + [rc log θ1 + gc log(1− θ1)] + [r" log θ2 + g" log(1− θ2)] Chapter 20, Sections 1–3 10 Multiple parameters Red/green wrapper depends probabilistically on flavor: P F=cherry( ) Flavor Wrapper P( )W=red | FF cherry 2lime θ 1θ θ Likelihood for, e.g., cherry candy in green wrapper: P (F = cherry ,W = green |hθ,θ1,θ2) = P (F = cherry |hθ,θ1,θ2)P (W = green |F = cherry , hθ,θ1,θ2) = θ · (1− θ1) N candies, rc red-wrapped cherry candies, etc.: P (d|hθ,θ1,θ2) = θc(1− θ)" · θrc1 (1− θ1)gc · θr!2 (1− θ2)g! L = [c log θ + " log(1− θ)] + [rc log θ1 + gc log(1− θ1)] + [r" log θ2 + g" log(1− θ2)] Chapter 20, Sections 1–3 10 Multiple parameters Red/green wrapper depends probabilistically on flavor: P F=cherry( ) Flavor Wrapper P( )W=red | FF cherry 2lime θ 1θ θ Likelihood for, e.g., cherry candy in green wrapper: P (F = cherry ,W = green |hθ,θ1,θ2) = P (F = cherry |hθ,θ1,θ2)P (W = green |F = cherry , hθ,θ1,θ2) = θ · (1− θ1) N candies, rc red-wrapped cherry candies, etc.: P (d|hθ,θ1,θ2) = θc(1− θ)" · θrc1 (1− θ1)gc · θr!2 (1− θ2)g! L = [c log θ + " log(1− θ)] + [rc log θ1 + gc log(1− θ1)] + [r" log θ2 + g" log(1− θ2)] Chapter 20, Sections 1–3 10 Multiple parameters Red/green wrapper depends probabilistically on flavor: P F=cherry( ) Flavor Wrapper P( )W=red | FF cherry 2lime θ 1θ θ Likelihood for, e.g., cherry candy in green wrapper: P (F = cherry ,W = green |hθ,θ1,θ2) = P (F = cherry |hθ,θ1,θ2)P (W = green |F = cherry , hθ,θ1,θ2) = θ · (1− θ1) N candies, rc red-wrapped cherry candies, etc.: P (d|hθ,θ1,θ2) = θc(1− θ)" · θrc1 (1− θ1)gc · θr!2 (1− θ2)g! L = [c log θ + " log(1− θ)] + [rc log θ1 + gc log(1− θ1)] + [r" log θ2 + g" log(1− θ2)] Chapter 20, Sections 1–3 10 Parâmetros múltiplos ¨ Derivadas de L contem somente o parâmetro relevante: ¨ Com , os . Multiple parameters contd. Derivatives of L contain only the relevant parameter: ∂L ∂θ = c θ − # 1− θ = 0 ⇒ θ = c c + # ∂L ∂θ1 = rc θ1 − gc 1− θ1 = 0 ⇒ θ1 = rc rc + gc ∂L ∂θ2 = r! θ2 − g! 1− θ2 = 0 ⇒ θ2 = r! r! + g! With complete data, parameters can be learned separately Chapter 20, Sections 1–3 11
Compartilhar