# NOT RUN {
# Load and scale data
data("USArrests")
df <- scale(USArrests)
# Enhanced k-means clustering
res.km <- eclust(df, "kmeans", nboot = 10)
# Silhouette plot
fviz_silhouette(res.km)
# Optimal number of clusters using gap statistics
res.km$nbclust
# Print result
res.km
# Enhanced hierarchical clustering
res.hc <- eclust(df, "hclust", nboot = 10) # compute hclust
fviz_dend(res.hc) # dendrogam
fviz_silhouette(res.hc) # silhouette plot
# }
Run the code above in your browser using DataLab