Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
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

Product type Book
Published in Aug 2018
Publisher Packt
ISBN-13 9781789537550
Pages 144 pages
Edition 1st Edition
Languages
Author (1):
Nisheeth Joshi Nisheeth Joshi
Profile icon Nisheeth Joshi
Toc

Table of Contents (14) Chapters close

Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
1. Introduction to Artificial Intelligence and Java 2. Exploring Search Algorithms 3. AI Games and the Rule-Based System 4. Interfacing with Weka 5. Handling Attributes 6. Supervised Learning 7. Semi-Supervised and Unsupervised Learning 1. Other Books You May Enjoy 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...

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 £13.99/month. Cancel anytime}