1 Loading Library

library(tidyverse)
library(clustMixType)

2 Data

iris %>% glimpse()
## Rows: 150
## Columns: 5
## $ Sepal.Length <dbl> 5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0, 4.4, 4.9, 5.4, 4.…
## $ Sepal.Width  <dbl> 3.5, 3.0, 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 3.7, 3.…
## $ Petal.Length <dbl> 1.4, 1.4, 1.3, 1.5, 1.4, 1.7, 1.4, 1.5, 1.4, 1.5, 1.5, 1.…
## $ Petal.Width  <dbl> 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.1, 0.2, 0.…
## $ Species      <fct> setosa, setosa, setosa, setosa, setosa, setosa, setosa, s…

3 Cluster Analysis

3.1 Find k

set.seed(7)

total_withinss <- c()

for (i in 1:8) {
  kproto <- clustMixType::kproto(iris,
                                 k = i,
                                 nstart = 25)
  total_withinss[i] <- kproto$tot.withinss
}
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## Estimated lambda: 1.714859 
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## Estimated lambda: 1.714859 
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## Estimated lambda: 1.714859 
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## Estimated lambda: 1.714859 
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## Estimated lambda: 1.714859 
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## Estimated lambda: 1.714859 
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## Estimated lambda: 1.714859 
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## Estimated lambda: 1.714859 
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
total_withinss
## [1] 852.85649 238.09090  87.95509  67.44546  51.15272  42.89405  35.62459
## [8]  33.28501
# identify ELBOW

tibble(k = 1:length(total_withinss),
       total_error = total_withinss
       ) %>% 
  ggplot(aes(x = k,
             y = total_error)
         ) +
  geom_point(size = 2) +
  geom_line() +
  theme_bw() +
  labs(x = "Number of Clusters",
       y = "tot.withinss") +
  geom_text(x = 3,
            y = total_withinss[3],
            label = "ELBOW",
            alpha = 0.5,
            color = "blue",
            size = 5)

3.2 Cluster

iris_kproto <- iris %>% 
clustMixType::kproto(k = 3,
                     nstart = 25)
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## Estimated lambda: 1.714859 
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
## 
## # NAs in variables:
## Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
##            0            0            0            0            0 
## 0 observation(s) with NAs.
iris_kproto
## Numeric predictors: 4 
## Categorical predictors: 1 
## Lambda: 1.714859 
## 
## Number of Clusters: 3 
## Cluster sizes: 50 49 51 
## Within cluster error: 15.151 39.15551 33.64858 
## 
## Cluster prototypes:
##   Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
## 1     5.006000    3.428000     1.462000    0.246000     setosa
## 2     6.622449    2.983673     5.573469    2.032653  virginica
## 3     5.915686    2.764706     4.264706    1.333333 versicolor
iris_kproto$cluster
##   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20 
##   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1 
##  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40 
##   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1 
##  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60 
##   1   1   1   1   1   1   1   1   1   1   3   3   3   3   3   3   3   3   3   3 
##  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80 
##   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3 
##  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 
##   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3 
## 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 
##   2   2   2   2   2   2   3   2   2   2   2   2   2   2   2   2   2   2   2   2 
## 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 
##   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2 
## 141 142 143 144 145 146 147 148 149 150 
##   2   2   2   2   2   2   2   2   2   2
iris_kproto$size
## clusters
##  1  2  3 
## 50 49 51

3.3 Viz

clustMixType::clprofiles(object = iris_kproto,
                         x = iris)

3.4 Summary

iris_kproto %>% 
  base::summary()
## Sepal.Length 
##   Min. 1st Qu. Median     Mean 3rd Qu. Max.
## 1  4.3     4.8    5.0 5.006000     5.2  5.8
## 2  5.6     6.3    6.5 6.622449     6.9  7.9
## 3  4.9     5.6    5.9 5.915686     6.3  7.0
## 
## -----------------------------------------------------------------
## Sepal.Width 
##   Min. 1st Qu. Median     Mean 3rd Qu. Max.
## 1  2.3     3.2    3.4 3.428000   3.675  4.4
## 2  2.2     2.8    3.0 2.983673   3.200  3.8
## 3  2.0     2.5    2.8 2.764706   3.000  3.4
## 
## -----------------------------------------------------------------
## Petal.Length 
##   Min. 1st Qu. Median     Mean 3rd Qu. Max.
## 1  1.0     1.4    1.5 1.462000   1.575  1.9
## 2  4.8     5.1    5.6 5.573469   5.900  6.9
## 3  3.0     4.0    4.4 4.264706   4.600  5.1
## 
## -----------------------------------------------------------------
## Petal.Width 
##   Min. 1st Qu. Median     Mean 3rd Qu. Max.
## 1  0.1     0.2    0.2 0.246000     0.3  0.6
## 2  1.4     1.8    2.0 2.032653     2.3  2.5
## 3  1.0     1.2    1.3 1.333333     1.5  1.8
## 
## -----------------------------------------------------------------
## Species 
##        
## cluster setosa versicolor virginica
##       1   1.00       0.00      0.00
##       2   0.00       0.00      1.00
##       3   0.00       0.98      0.02
## 
## -----------------------------------------------------------------

3.5 Append 3-Prototypes Clustering assigments to dataset

iris_kproto$cluster
##   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20 
##   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1 
##  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40 
##   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1 
##  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60 
##   1   1   1   1   1   1   1   1   1   1   3   3   3   3   3   3   3   3   3   3 
##  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80 
##   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3 
##  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 
##   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3 
## 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 
##   2   2   2   2   2   2   3   2   2   2   2   2   2   2   2   2   2   2   2   2 
## 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 
##   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2 
## 141 142 143 144 145 146 147 148 149 150 
##   2   2   2   2   2   2   2   2   2   2
iris1 <- iris %>% 
  mutate(kproto_cluster = iris_kproto$cluster)

iris1 %>% 
  glimpse()
## Rows: 150
## Columns: 6
## $ Sepal.Length   <dbl> 5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0, 4.4, 4.9, 5.4, …
## $ Sepal.Width    <dbl> 3.5, 3.0, 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 3.7, …
## $ Petal.Length   <dbl> 1.4, 1.4, 1.3, 1.5, 1.4, 1.7, 1.4, 1.5, 1.4, 1.5, 1.5, …
## $ Petal.Width    <dbl> 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.1, 0.2, …
## $ Species        <fct> setosa, setosa, setosa, setosa, setosa, setosa, setosa,…
## $ kproto_cluster <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…

3.6 Convert cluster 3-prototypes cluster assigment to specie name

iris1$kproto_cluster[iris1$kproto_cluster == 1] <- "virginica"
iris1$kproto_cluster[iris1$kproto_cluster == 2] <- "versicolor"
iris1$kproto_cluster[iris1$kproto_cluster == 3] <- "setosa"

table(iris1$Species, iris1$kproto_cluster)
##             
##              setosa versicolor virginica
##   setosa          0          0        50
##   versicolor     50          0         0
##   virginica       1         49         0

3.7 Find 1 disagreement

iris1 %>% 
  ggplot(aes(x = Petal.Length,
             y = Petal.Width,
             color = kproto_cluster)) +
  geom_point() +
  geom_point(color = "black",
             size = 4,
             shape = 13,
             data = iris1[iris1$Species != iris1$kproto_cluster, ])