O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

Perform the following steps to perform cluster validation using the proteinIntake dataset:

  1. First, load the protein.csv file and do some preprocessing to scale and alter the row names:
> proteinIntake <- read.csv("protein.csv")> rownames(proteinIntake)=proteinIntake$Country> proteinIntake$Country=NULL> proteinIntakeScaled = as.data.frame(scale(proteinIntake))
  1. Compute the optimal number of clusters and visualize the result:
> nb <- NbClust(proteinIntakeScaled, distance = "euclidean", min.nc = 2,max.nc = 9, method = "ward.D2", index ="all")> fviz_nbclust(nb) + theme_minimal()

The following figure gives us an idea of the computations:

The following image gives us a plot of the number of clusters versus frequency:

  1. Next, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required