BaşlayınÜcretsiz başlayın

Expectation function

So far, you have learned how the Expectation-Maximization algorithm is used to estimate the parameters of two Gaussian distributions with both sd equal 1. The aim of this exercise is to create the function expectation, which generalizes the step of estimating the probabilities when we know the means, proportions and the sds.

Bu egzersiz, kursun bir parçasıdır

Mixture Models in R

Kursa Göz Atın

Egzersiz talimatları

Create the function expectation by completing the sample code. Observe that we are now considering the standard deviations of each cluster as its fourth parameter.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

expectation <- ___(___, means, proportions, ___){
  # Estimate the probabilities
  exp_data <- data %>% 
    mutate(prob_from_cluster1 = ___[1] * dnorm(x, mean = means[1], sd = ___[1]),
           prob_from_cluster2 = ___[2] * dnorm(x, mean = means[2], sd = ___[2]),
           prob_cluster1 = prob_from_cluster1/(prob_from_cluster1 + prob_from_cluster2),
           prob_cluster2 = prob_from_cluster2/(prob_from_cluster1 + prob_from_cluster2)) %>% 
    select(x, ___, ___)
    
  # Return data with probabilities
  return(exp_data)
}
Kodu Düzenle ve Çalıştır