Gaussian karışım modelleri (GMM)

R ile Karışım Modelleri

Victor Medina

Researcher at The University of Edinburgh

Yazı tura ve örnekleme

  • Yazı

  • Tura

R ile Karışım Modelleri
# Gözlem sayısı
number_of_obs <- 500 
# Parayı simüle et
coin <- sample(c(0,1), size = number_of_obs, 
                replace = TRUE, prob = c(0.5, 0.5)) 
head(coin)
0 1 0 1 0 0
table(coin)
coin
  0   1 
239 261
R ile Karışım Modelleri
# Gaussian 1 "yazı"
gauss_1 <- rnorm(n = number_of_obs, mean = 5, sd = 2)
# Gaussian 2 "tura"
gauss_2 <- rnorm(n = number_of_obs)

# Karışımı simüle et mixture_simulation <- ifelse(coin, gauss_1, gauss_2) head(cbind(coin, gauss_1, gauss_2, mixture_simulation))
     coin  gauss_1    gauss_2 mixture_simulation
[1,]    0 7.378712 -0.4559596         -0.4559596
[2,]    1 6.102770  3.3595880          6.1027696
[3,]    0 5.707269 -0.0731496         -0.0731496
[4,]    1 3.592059 -1.2407104          3.5920586
[5,]    0 5.236851 -0.5110058         -0.5110058
[6,]    0 4.152619 -0.5124031         -0.5124031
R ile Karışım Modelleri

Karışımı görselleştir

# Veri çerçevesine dönüştür
mixture_simulation <- data.frame(x = mixture_simulation)

# Histogramı oluştur
ggplot(mixture_simulation) + 
     geom_histogram(aes(x = x, ..density..), bins = 40)
R ile Karışım Modelleri

R ile Karışım Modelleri

Oranları değiştirmek

# Farklı oranlarla parayı simüle et
coin <- sample(c(0,1), size = number_of_obs, 
                replace = TRUE, prob = c(0.8, 0.2))

# Karışımı simüle et
mixture_simulation <- data.frame(x = ifelse(coin, gauss_1, gauss_2))

# Histogramı oluştur
ggplot(mixture_simulation) + 
   geom_histogram(aes(x = x, ..density..), bins = 40)
R ile Karışım Modelleri

R ile Karışım Modelleri

Üç dağılımın karışımı

proportions <- sample(c(0, 1, 2), number_of_obs, 
                       replace = TRUE, prob = c(1/3, 1/3, 1/3))

gauss_3 <- rnorm(n = number_of_obs, mean = 10, sd = 1) 

mixture_simulation <- data.frame(x = ifelse(proportions == 0, gauss_1, 
                            ifelse(proportions == 1, gauss_2, gauss_3)))

ggplot(mixture_simulation) + 
   geom_histogram(aes(x = x, ..density..), bins = 40)
R ile Karışım Modelleri

R ile Karışım Modelleri

Hadi pratik yapalım!

R ile Karışım Modelleri

Preparing Video For Download...