0

I am relatively new to Java, and as a learning experience, tried to build a classifier in java by reading a dataset from a file called "dataset.csv"

This is the code I wrote for the whole class:

import java.io.IOException;
import weka.classifiers.trees.J48;
import weka.classifiers.Classifier;
import weka.classifiers.Evaluation;
import weka.core.converters.CSVLoader;
import weka.core.Instances;

public class classifier {
    public static final String DATASET = "dataset.csv";
    
    public static Instances getData(String filename) throws IOException
    {
        CSVLoader loader = new CSVLoader();
        loader.setSource(classifier.class.getResourceAsStream("/"+filename));
        System.out.println("getData function running");
        Instances dataset = loader.getDataSet();
        
        return dataset;
    }
    
    public static void J48Classifier() throws Exception
    {
        
        Instances dataset = getData(DATASET);
        Classifier j48 = new J48();
        
        j48.buildClassifier(dataset);
        
        Evaluation eval = new Evaluation(dataset);
        eval.evaluateModel(j48,dataset);
        
        System.out.println("Evaluation with dataset: ");
        System.out.println(eval.toSummaryString());
        
        System.out.println("Expression as per the algorithm: ");
        System.out.println(j48);
        
        System.out.println(eval.toMatrixString());
        System.out.println(eval.toClassDetailsString());    
    }
    
    public static void main(String args[]) throws Exception
    {
        J48Classifier();
    }
}


But once I run the code, I am getting this error:

enter image description here

This is my file Structure for reference (the dataset.csv file is located in the src directory of the below cited image):

enter image description here

Can anyone help me figure out if I have missed out on something?

Purohit Iyer
  • 53
  • 1
  • 4

0 Answers0