Create weka Instances to load data file - Java Machine Learning AI

Java examples for Machine Learning AI:weka

Description

Create weka Instances to load data file

Demo Code


import java.io.BufferedReader;
import java.io.FileReader;

import weka.classifiers.functions.LinearRegression;
import weka.core.Instance;
import weka.core.Instances;

public class WekaDemo {

  public static void main(String[] args) throws Exception {

    Instances data = new Instances(new BufferedReader(new FileReader("./gasPriceV3.arff")));

    data.setClassIndex(data.numAttributes() - 1);

    LinearRegression linearRegression = new LinearRegression();

    linearRegression.buildClassifier(data);

    System.out.println(linearRegression);
    //from   w  w  w.j a  va2s  .c om
    for(int i=19765;i<data.numInstances();i++){
      Instance prediction = data.instance(i);

      double price = linearRegression.classifyInstance(prediction);

      System.out.println(price);
    }
    
  }

}

Related Tutorials