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

Reading and writing datasets


We will now look at how to read and write a dataset. Let's get to our Java code. Create a project and name it Datasets. Now, import the weka.jar file, as performed in the previous section. Once we have the weka.jar file available, we can read the core, Instance interfaces, ArffSaver, DataSource, and io.File packages, as shown in the following screenshot:

We will start with DataSource. DataSource is a class that helps us to open a dataset file that is available in Weka. By default, Weka works with ARFF files; see the following code:

DataSource src = new DataSource("/Users/admin/wekafiles/data/weather.numeric.arff");
Instances dt= src.getDataSet();
System.out.println(dt.toSummaryString());
ArffSaver as = new ArffSaver();

As we can see in the preceding code, we created an object for DataSource and provided a path to the ARFF file that we need to open. This will only provide a path to an ARFF file; it will not open it. In the working memory, there is a class called...