Skip to content

Commit

Permalink
cluster analysis post final
Browse files Browse the repository at this point in the history
  • Loading branch information
PetoLau committed Jan 11, 2024
1 parent b9a0de0 commit 0a2357f
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion _posts/2024-01-11-Overview-clustering-methods-in-R.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ author: "Peter Laurinec"
layout: post
published: true
status: publish
tags: clustering
tags: R clustering
draft: no
---

Expand Down
12 changes: 6 additions & 6 deletions _rmd/2024-01-11-Overview-clustering-methods-in-R.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ title: "Overview of clustering methods in R"
author: "Peter Laurinec"
layout: post
published: no
status: process
tags: clustering
status: processed
tags: R clustering
draft: no
---

Expand Down Expand Up @@ -233,7 +233,7 @@ The Elbow diagram is a simple method (rule) how to determine the number of clust

So for example, I chose the Davies-Bouldin index implemented in the `clusterCrit` package. For our simple dataset, I will generate clusterings with 2-6 number of clusters and compute the index.

```{r, fig.width=8, fig.height=6.5, warning=FALSE}
```{r, fig.width=8, fig.height=5.5, warning=FALSE}
library(clusterCrit)
km_res_k <- lapply(2:6, function(i) kmeans(data_example[, .(x, y)], i)$cluster)
Expand Down Expand Up @@ -263,7 +263,7 @@ We can see that the Elbow diagram rule chose 4 clusters - makes sense to me actu

We can also try it with PAM - K-medoids.

```{r, fig.width=8, fig.height=6.5}
```{r, fig.width=8, fig.height=5.5}
kmed_res_k <- lapply(2:6, function(i) pam(data_example[, .(x, y)], i)$clustering)
db_kmed <- lapply(kmed_res_k, function(j) intCriteria(data.matrix(data_example[, .(x, y)]),
Expand Down Expand Up @@ -316,7 +316,7 @@ Pros and cons:

EM algorithm with GMM is implemented in the `mclust` package. You can optimize various shapes of mixtures (clusters) by the `modelNames` parameter (check the `?mclustModelNames` function for more details).

```{r, message=FALSE, warning=FALSE, fig.height=8, fig.width=6.5}
```{r, message=FALSE, warning=FALSE, fig.height=6.5, fig.width=8}
library(mclust)
res <- Mclust(data_example[, .(x, y)], G = 3, modelNames = "VVV", verbose = FALSE)
Expand All @@ -339,7 +339,7 @@ plot(res, what = "BIC")
```

The result:
```{r, fig.height=8, fig.width=6.5}
```{r, fig.height=6.5, fig.width=8}
plot(res, what = "classification")
```

Expand Down
Binary file modified images/post_16/unnamed-chunk-10-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/post_16/unnamed-chunk-12-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/post_16/unnamed-chunk-6-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/post_16/unnamed-chunk-8-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0a2357f

Please sign in to comment.