Skip to Content
Machine Learning in Java - Second Edition
book

Machine Learning in Java - Second Edition

by AshishSingh Bhatia, Bostjan Kaluza
November 2018
Intermediate to advanced
300 pages
7h 42m
English
Packt Publishing
Content preview from Machine Learning in Java - Second Edition

Clustering using Encog

Encog supports k-means clustering. Let's consider a very simple example, with the data shown in the following code block:

DATA = { { 28, 15, 22 }, { 16, 15, 32 }, { 32, 20, 44 }, { 1, 2, 3 }, { 3, 2, 1 } };

To make BasicMLDataSet from this data, a simple for loop is used, which will add data to the dataset:

BasicMLDataSet set = new BasicMLDataSet();for (final double[] element : DATA) {    set.add(new BasicMLData(element));}

Using the KMeansClustering function, let's clusters the dataset into two clusters, as follows:

KMeansClustering kmeans = new KMeansClustering(2, set);kmeans.iteration(100);// Display the clusterint i = 1;for (MLCluster cluster : kmeans.getClusters()) { System.out.println("*** Cluster " + (i++) + " ***"); ...
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

Mastering Java Machine Learning

Mastering Java Machine Learning

Uday Kamath, Krishna Choppella
Java: Data Science Made Easy

Java: Data Science Made Easy

Richard M. Reese, Jennifer L. Reese, Alexey Grigorev

Publisher Resources

ISBN: 9781788474399Supplemental Content