Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Artificial Intelligence with Java for Beginners

You're reading from   Hands-On Artificial Intelligence with Java for Beginners Build intelligent apps using machine learning and deep learning with Deeplearning4j

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher Packt
ISBN-13 9781789537550
Length 144 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Nisheeth Joshi Nisheeth Joshi
Author Profile Icon Nisheeth Joshi
Nisheeth Joshi
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Preface 1. Introduction to Artificial Intelligence and Java 2. Exploring Search Algorithms FREE CHAPTER 3. AI Games and the Rule-Based System 4. Interfacing with Weka 5. Handling Attributes 6. Supervised Learning 7. Semi-Supervised and Unsupervised Learning 8. Other Books You May Enjoy

Evaluating a clustering model


Now, we'll look at how to evaluate a clustering model that has been trained. Let's look at the code and see how this is done.

We'll be using the following classes:

import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
import weka.clusterers.SimpleKMeans;
import weka.clusterers.ClusterEvaluation;

We'll use the ClusterEvaluation class from the weka.clusterers package for evaluation.

First, we will read our dataset into our DataSource object and assign it to the Instances object. Then, we'll create our k-means object and specify the number of clusters that we want to create. Next, we will train our clustering algorithm using the buildClusterer method; then, we'll print it using println. This is similar to what you saw earlier:

public static void main(String[] args) {
    // TODO code application logic here
    try{
        DataSource src = new DataSource("/Users/admin/Documents/NetBeansProjects/ClusterEval/weather.arff");
        Instances...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime