Apply the two steps
Since you have created the functions expectation and maximization, you can now apply the EM algorithm to a data frame.
The objective in this exercise is to find two Gaussian clusters in the data gaussian_sample. Assume both sd are equal to 10.
This exercise is part of the course
Mixture Models in R
Exercise instructions
- Start with the guess that one of the clusters has a mean of
0and the other100. Use the functionsexpectationandmaximizationto create a list,new_values. - Save these values into the vector
means_init. Consider the proportions are equal in the vectorprops_init. - Go through 10 iterations.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
means_init <- c(0, 100)
___ <- c(0.5, 0.5)
# Iterative process
for(i in 1:___){
___ <- maximization(___(gaussian_sample, means_init, props_init, c(10, 10)))
means_init <- new_values[[1]]
props_init <- ___[[2]]
cat(c(i, means_init, props_init), "\n")
}