Reader small image

You're reading from  Hands-On Artificial Intelligence with Java for Beginners

Product typeBook
Published inAug 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781789537550
Edition1st Edition
Languages
Right arrow
Author (1)
Nisheeth Joshi
Nisheeth Joshi
author image
Nisheeth Joshi

Nisheeth Joshi is an associate professor and a researcher at Banasthali University. He has also done a PhD in Natural Language Processing. He is an expert with the TDIL Program, Department of IT, Government of India, the premier organization overseeing language technology funding and research in India. He has several publications to his name in various journals and conferences, and also serves on the program committees and editorial boards of several conferences and journals.
Read more about Nisheeth Joshi

Right arrow

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 page is locked
Previous PageNext Page
You have been reading a chapter from
Hands-On Artificial Intelligence with Java for Beginners
Published in: Aug 2018Publisher: PacktISBN-13: 9781789537550

Author (1)

author image
Nisheeth Joshi

Nisheeth Joshi is an associate professor and a researcher at Banasthali University. He has also done a PhD in Natural Language Processing. He is an expert with the TDIL Program, Department of IT, Government of India, the premier organization overseeing language technology funding and research in India. He has several publications to his name in various journals and conferences, and also serves on the program committees and editorial boards of several conferences and journals.
Read more about Nisheeth Joshi