Skip to Content
Java: Data Science Made Easy
book

Java: Data Science Made Easy

by Richard M. Reese, Jennifer L. Reese, Alexey Grigorev
July 2017
Beginner to intermediate
715 pages
17h 3m
English
Packt Publishing
Content preview from Java: Data Science Made Easy

Choosing K in K-Means

K-means has a drawback: we need to specify the number of clusters K. Sometimes K can be known from the domain problem we are trying to solve. For example, if we know that there are 10 types of clients, we probably want to look for 10 clusters.

However, often we do not have this kind of domain knowledge. In situations like this, we can use a method often referred as the elbow method:

  • Try different values of K, record the distortion for each
  • Plot the distortion for each K
  • Try to spot the elbow, the part of the graph where the error stops dropping rapidly and starts decreasing slowly

You can do it in the following way:

PrintWriter out = new PrintWriter("distortion.txt"); for (int k = 3; k < 50; k++) {  int maxIter = ...
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

Java Data Science Cookbook

Java Data Science Cookbook

Rushdi Shams
Java for Data Science

Java for Data Science

Walter Molina, Richard M. Reese, Shilpi Saxena, Jennifer L. Reese

Publisher Resources

ISBN: 9781788475655Supplemental Content