Skip to Content
Practical Predictive Analytics
book

Practical Predictive Analytics

by Ralph Winters
June 2017
Beginner to intermediate content levelBeginner to intermediate
576 pages
15h 22m
English
Packt Publishing
Content preview from Practical Predictive Analytics

Cluster elbow plot

One way to determine this is by using an automated method known as the elbow method in which you plot the total within clusters sum of squares for all values within a range, and look at where an elbow method develops in the plot:

#elbow method 
set.seed(1020) 
# Compute and plot wss for k = 3 to k = 15 
df <- sapply(3:15,function(k){kmeans(y,k)$tot.withinss}) 
 
plot(3:15, df,type='b',xlab="# of clusters",ylab="Total Within Clusters SS") 

In the following plot, you might see two elbows, one at 5-6 cluster, and one at 8-9. We will assume for now that five is the optimal number, only because there is an elbow in that area, and the names given to the clusters will be easier to explain:

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Data Superstream: Analytics Engineering

Data Superstream: Analytics Engineering

Alistair Croll, Anna Filippova, Emilie Schario, Lewis Davies, Jacob Frackson, Benn Stancil, Nick Acosta, Elizabeth Caley
R: Predictive Analysis

R: Predictive Analysis

Tony Fischetti, Eric Mayor, Rui Miguel Forte
Python: Advanced Predictive Analytics

Python: Advanced Predictive Analytics

Ashish Kumar, Joseph Babcock

Publisher Resources

ISBN: 9781785886188Supplemental Content