Aktüerya Uygulamaları

K-ORTALAMALAR KÜMELEME ANALİZİ

2024-05-23

ÖDEVİ HAZIRLAYANLAR

  • KARDELEN KAYA
  • DAMLA BİNGÜL
  • AHMET AKTAŞ
  • ŞAMİL DOĞUKAN AKTAŞ

K-ORTALAMALAR KÜMELEME ANALİZİ

YAPAY VERİ OLUŞTURMA VE ANALİZ KODLARI

chooseCRANmirror(ind=1)  # Örnek bir CRAN aynası seçimi
# Gerekli paketleri yükleyin
install.packages("ggplot2")
## Installing package into 'C:/Users/zeraa/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'ggplot2' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\zeraa\AppData\Local\Temp\Rtmpakyhz5\downloaded_packages
install.packages("factoextra")
## Installing package into 'C:/Users/zeraa/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'factoextra' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\zeraa\AppData\Local\Temp\Rtmpakyhz5\downloaded_packages
library(ggplot2)
library(factoextra)
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
# Rastgele bir sosyal medya veri seti oluşturun (1000 gözlem)
set.seed(123)
veri <- data.frame(
  Gunluk_Mesaj_Sayisi = rpois(1000, 10),     # Ortalama 10 mesaj
  Takipci_Sayisi = rnorm(1000, 1000, 200),   # Ortalama 1000 takipçi
  Begeni_Orani = runif(1000, 0, 1),          # 0 ile 1 arasında beğeni oranı
  Paylasim_Sikligi = rpois(1000, 5),         # Ortalama 5 paylaşım
  Yorum_Sayisi = rpois(1000, 20),            # Ortalama 20 yorum
  Etiket_Sayisi = rpois(1000, 15),           # Ortalama 15 etiket
  Video_Izlenme_Suresi = rnorm(1000, 300, 50),  # Ortalama 300 saniye video izlenme süresi
  Hikaye_Goruntulenme_Sayisi = rnorm(1000, 150, 30)  # Ortalama 150 hikaye görüntülenme sayısı
)


head(veri)
##   Gunluk_Mesaj_Sayisi Takipci_Sayisi Begeni_Orani Paylasim_Sikligi Yorum_Sayisi
## 1                   8       944.5004    0.0193967                7           18
## 2                   9      1130.7818    0.7588939                8           24
## 3                  14      1016.0700    0.1576183                5           23
## 4                  10      1091.1805    0.1122757                6           17
## 5                  10      1166.9064    0.7138137                6           20
## 6                  15       861.4552    0.4452190                8           23
##   Etiket_Sayisi Video_Izlenme_Suresi Hikaye_Goruntulenme_Sayisi
## 1            15             317.8749                   206.6020
## 2            10             318.1635                   141.1547
## 3            12             246.1178                   115.7472
## 4            20             319.2866                   237.7997
## 5            10             389.0653                   135.3836
## 6            26             285.1380                   190.4248
# Optimal K değerini belirleyin
set.seed(123)
fviz_nbclust(veri, kmeans, method = "wss")

# K-Means kümeleme analizini gerçekleştirin (K=3)
set.seed(123)
km.sonuc <- kmeans(veri, 5, nstart = 25)
print(km.sonuc)
## K-means clustering with 5 clusters of sizes 252, 232, 110, 294, 112
## 
## Cluster means:
##   Gunluk_Mesaj_Sayisi Takipci_Sayisi Begeni_Orani Paylasim_Sikligi Yorum_Sayisi
## 1            9.809524        845.944    0.4830489         4.805556     19.59524
## 2           10.073276       1151.357    0.4991119         5.193966     20.25000
## 3           10.300000        657.817    0.4846522         5.181818     19.80000
## 4            9.959184       1003.717    0.4720756         5.061224     20.07823
## 5            9.937500       1345.320    0.5167988         4.910714     20.53571
##   Etiket_Sayisi Video_Izlenme_Suresi Hikaye_Goruntulenme_Sayisi
## 1      15.00000             297.1327                   148.1044
## 2      14.76293             298.6731                   147.7800
## 3      15.16364             299.9764                   149.2000
## 4      15.12585             302.4136                   150.0510
## 5      15.45536             302.1767                   144.6540
## 
## Clustering vector:
##    [1] 4 2 4 2 2 1 3 2 3 4 1 2 5 1 4 4 1 1 3 3 1 4 4 1 1 1 1 1 4 2 1 5 2 1 1 2 1
##   [38] 4 2 4 1 1 4 4 1 4 1 5 3 5 4 4 3 2 5 1 2 5 5 1 1 4 4 1 1 2 4 2 1 2 4 4 3 3
##   [75] 2 3 1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 1 1
##  [556] 5 4 5 2 2 4 2 2 3 4 4 2 5 5 2 4 5 2 3 1 4 2 1 2 3 4 4 5 5 4 4 4 2 4 1 4 1
##  [593] 1 4 2 2 4 5 1 4 1 2 4 4 2 1 4 5 1 2 1 2 4 2 4 2 5 1 1 2 4 5 4 4 1 5 2 3 5
##  [630] 1 1 1 3 2 3 1 1 2 1 4 1 2 1 5 4 1 5 4 1 1 2 1 5 1 3 3 1 2 3 1 4 3 4 3 3 5
##  [667] 5 2 5 1 5 1 2 3 2 3 3 1 1 4 4 5 5 2 1 4 4 2 4 1 2 3 4 1 4 2 4 2 4 1 1 4 5
##  [704] 3 4 1 1 2 4 5 1 3 1 1 2 4 2 4 2 2 2 1 1 2 2 1 2 1 4 1 1 3 4 1 1 1 4 4 2 2
##  [741] 2 3 4 3 5 4 1 4 4 2 2 3 2 3 2 3 4 4 5 1 5 3 1 1 1 2 2 3 1 3 2 2 2 5 4 4 1
##  [778] 5 4 1 1 5 1 2 4 2 2 1 3 5 5 1 5 2 4 2 4 2 4 2 4 4 5 2 2 4 4 3 1 2 4 1 2 1
##  [815] 4 1 1 2 1 4 4 1 5 2 4 3 2 5 2 2 1 3 4 5 4 1 5 1 2 2 4 4 1 4 2 2 1 5 2 3 4
##  [852] 5 3 1 2 2 1 2 1 1 3 2 4 4 5 1 1 1 4 5 2 1 2 1 1 2 2 4 3 2 4 2 3 2 4 3 4 4
##  [889] 2 3 2 4 4 1 4 4 1 4 4 1 4 5 4 3 1 2 3 1 3 2 4 5 5 4 4 4 2 2 4 5 2 4 3 4 3
##  [926] 2 2 4 4 4 4 1 3 4 4 5 5 2 1 3 2 1 2 4 1 1 4 1 4 1 5 4 4 4 1 5 4 4 4 1 4 5
##  [963] 1 1 5 3 4 2 2 2 1 2 2 3 2 4 4 4 4 2 5 4 3 2 4 5 1 4 2 2 1 1 5 1 4 2 2 5 3
## [1000] 4
## 
## Within cluster sum of squares by cluster:
## [1] 1412351 1274650 1129459 1536635 1196835
##  (between_SS / total_SS =  85.1 %)
## 
## Available components:
## 
## [1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
## [6] "betweenss"    "size"         "iter"         "ifault"
# K-means sonuçlarını görselleştirin
fviz_cluster(km.sonuc, data = veri, ellipse.type = "convex", geom = "point", stand = FALSE) +
  theme_minimal()

ANALİZ SONUÇLARI

K-means clustering with 5 clusters of sizes 252, 232, 110, 294, 112

Cluster means: Gunluk_Mesaj_Sayisi Takipci_Sayisi Begeni_Orani Paylasim_Sikligi Yorum_Sayisi Etiket_Sayisi Video_Izlenme_Suresi 1 9.809524 845.944 0.4830489 4.805556 19.59524 15.00000 297.1327 2 10.073276 1151.357 0.4991119 5.193966 20.25000 14.76293 298.6731 3 10.300000 657.817 0.4846522 5.181818 19.80000 15.16364 299.9764 4 9.959184 1003.717 0.4720756 5.061224 20.07823 15.12585 302.4136 5 9.937500 1345.320 0.5167988 4.910714 20.53571 15.45536 302.1767 Hikaye_Goruntulenme_Sayisi 1 148.1044 2 147.7800 3 149.2000 4 150.0510 5 144.6540

Clustering vector: [1] 4 2 4 2 2 1 3 2 3 4 1 2 5 1 4 4 1 1 3 3 1 4 4 1 1 1 1 1 4 2 1 5 2 1 1 2 1 4 2 4 1 1 4 4 1 4 1 5 3 5 4 4 3 2 5 1 [57] 2 5 5 1 1 4 4 1 1 2 4 2 1 2 4 4 3 3 2 3 1 4 2 4 2 3 2 2 1 4 2 1 1 4 1 4 2 4 5 1 2 4 1 3 2 4 3 4 4 5 1 2 1 3 2 3 [113] 4 2 2 1 1 2 4 1 1 1 3 2 4 1 5 2 5 5 1 4 5 2 5 2 4 5 2 4 4 1 5 1 4 3 5 5 1 1 2 4 4 2 2 1 3 2 3 4 1 4 4 5 4 1 4 4 [169] 1 4 4 4 2 3 1 2 5 4 3 5 4 4 4 2 2 4 3 4 5 5 4 2 1 5 2 4 2 4 1 4 4 2 4 4 2 4 2 2 1 1 1 3 4 5 2 1 1 2 5 4 3 1 2 1 [225] 5 2 4 5 3 2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 2 1 [729] 4 1 1 3 4 1 1 1 4 4 2 2 2 3 4 3 5 4 1 4 4 2 2 3 2 3 2 3 4 4 5 1 5 3 1 1 1 2 2 3 1 3 2 2 2 5 4 4 1 5 4 1 1 5 1 2 [785] 4 2 2 1 3 5 5 1 5 2 4 2 4 2 4 2 4 4 5 2 2 4 4 3 1 2 4 1 2 1 4 1 1 2 1 4 4 1 5 2 4 3 2 5 2 2 1 3 4 5 4 1 5 1 2 2 [841] 4 4 1 4 2 2 1 5 2 3 4 5 3 1 2 2 1 2 1 1 3 2 4 4 5 1 1 1 4 5 2 1 2 1 1 2 2 4 3 2 4 2 3 2 4 3 4 4 2 3 2 4 4 1 4 4 [897] 1 4 4 1 4 5 4 3 1 2 3 1 3 2 4 5 5 4 4 4 2 2 4 5 2 4 3 4 3 2 2 4 4 4 4 1 3 4 4 5 5 2 1 3 2 1 2 4 1 1 4 1 4 1 5 4 [953] 4 4 1 5 4 4 4 1 4 5 1 1 5 3 4 2 2 2 1 2 2 3 2 4 4 4 4 2 5 4 3 2 4 5 1 4 2 2 1 1 5 1 4 2 2 5 3 4

Within cluster sum of squares by cluster: [1] 1412351 1274650 1129459 1536635 1196835 (between_SS / total_SS = 85.1 %)

Available components:

[1] “cluster” “centers” “totss” “withinss” “tot.withinss” “betweenss” “size”
[8] “iter” “ifault”