Book Image

Hands-On Artificial Intelligence with Java for Beginners

By : Nisheeth Joshi
Book Image

Hands-On Artificial Intelligence with Java for Beginners

By: Nisheeth Joshi

Overview of this book

Artificial intelligence (AI) is increasingly in demand as well as relevant in the modern world, where everything is driven by technology and data. AI can be used for automating systems or processes to carry out complex tasks and functions in order to achieve optimal performance and productivity. Hands-On Artificial Intelligence with Java for Beginners begins by introducing you to AI concepts and algorithms. You will learn about various Java-based libraries and frameworks that can be used in implementing AI to build smart applications. In addition to this, the book teaches you how to implement easy to complex AI tasks, such as genetic programming, heuristic searches, reinforcement learning, neural networks, and segmentation, all with a practical approach. By the end of this book, you will not only have a solid grasp of AI concepts, but you'll also be able to build your own smart applications for multiple domains.
Table of Contents (14 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

Model evaluation


We will now look at how to evaluate the classifier that we have trained. Let's start with the code.

We'll start by importing the following classes:

import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
import weka.classifiers.trees.J48;
import weka.classifiers.Evaluation;
import java.util.Random;

This time, we'll use the Evaluation class from the weka.classifiers package, and a Random class for some random value generation.

 

The DataSource that we'll be using is the segment-challenge.arff file. We are using this because it has a test dataset, and it is also one of the datasets that comes with Weka. We'll assign it to our Instances object, and we will then tell Weka which attribute is the class attribute. We'll set the flags for our decision tree classifier and create an object for our decision tree classifier. Then, we'll set the options, and we'll build the classifier. We performed the same in the previous section:

public static void main(String...