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"); ...

Get Hands-On Artificial Intelligence with Java for Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.