Converting datasets
In this section, we will look at how to convert a dataset. We will learn how to convert a CSV file to an ARFF file, and vice versa.
Converting an ARFF file to a CSV file
First, let's look at the code. Suppose that we have a weather.arff
file. We will first import the following packages:
import weka.core.Instances; import weka.core.converters.ArffLoader; import weka.core.converters.CSVSaver; import java.io.File;
We have started with the ArffLoader
class, and have created an object, loader
, for it:
ArffLoader loader = new ArffLoader();
We have then assigned a filename, weather.arff
, to the ArffLoader
class, as seen in the following code:
loader.setSource(new File("weather.arff")); //Use the path where your file is saved.
We have also called the loader.setSource
method and assigned a filename to it by using our File
object. Once this is done, we will load this particular dataset into the memory in our Instances
object, data
, as follows:
Instances data = loader.getDataSet();
Now,...