'Hierarchical clustering: Calcuating amountof clusters

I am working with R.

I am calculating a hierarchical cluster and plotting it. I then cut it into cluster-groups to plot again.

I have a for-loop, to do this on subsets of a database, which works fine.

The problem is, each subset of data might have a different optimal number of clusters... The solutions ive found online, to find the optimal amount of clusters, is visual.

Is there code I can run to automiatically configure the optimal number of clusters? In the code example, im looking for "noOfClusters". Also, it should be a maximum of 10...

This is how my clustering looks like, in short:

clusterResult <- agnes(singleLinkMatrix,stand = FALSE, method = "ward", metric = "euclidean")
plot(clusterResult)
clusterMember <- cutree(clusterResult, k = noOfClusters)

Thanks a lot :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source