I am having a hard time finding a good tutorial for WEKA using its k-Means methods. Here is the code:
System.out.println("loading training data");
String path = System.getProperty("user.dir");
// Read all the instances in the file (ARFF, CSV, XRFF, ...)
Instances instances = null;
try {
DataSource source = new DataSource(path+"/data/train/class1_1.csv");
instances = source.getDataSet();
} catch (Exception e) {
e.printStackTrace();
return;
}
System.out.println("training data loaded");
// Make the last attribute be the class
instances.setClassIndex(instances.numAttributes() - 1);
// Print header and instances.
System.out.println("\ndataset:\n");
System.out.println(instances);
I am getting the error:
loading training data
---Registering Weka Editors---
Trying to add JDBC driver: RmiJdbc.RJDriver - Error, not in CLASSPATH?
Trying to add JDBC driver: jdbc.idbDriver - Error, not in CLASSPATH?
Trying to add JDBC driver: org.gjt.mm.mysql.Driver - Error, not in CLASSPATH?
Trying to add JDBC driver: com.mckoi.JDBCDriver - Error, not in CLASSPATH?
Trying to add JDBC driver: org.hsqldb.jdbcDriver - Error, not in CLASSPATH?
java.io.IOException: Stream closed
at java.io.BufferedReader.ensureOpen(BufferedReader.java:122)
at java.io.BufferedReader.read(BufferedReader.java:179)
at java.io.StreamTokenizer.read(StreamTokenizer.java:500)
at java.io.StreamTokenizer.nextToken(StreamTokenizer.java:544)
at weka.core.converters.ConverterUtils.getFirstToken(Unknown Source)
at weka.core.converters.CSVLoader.getInstance(Unknown Source)
at weka.core.converters.CSVLoader.getDataSet(Unknown Source)
at weka.core.converters.ConverterUtils$DataSource.getDataSet(Unknown Source)
at hmm.HMM.run(HMM.java:49)
at hmm.HMM.main(HMM.java:19)
training data loadedException in thread "main" java.lang.NullPointerException
at hmm.HMM.run(HMM.java:58)
at hmm.HMM.main(HMM.java:19)
Here is a photo of the csv file:

I am not even trying to connect to a database, I am trying to read a csv file I have. Anyone know how to load multiple csv files with weka?
First of all that JDBC warning messages are nothing to worry about, read here.
Following code read csv files and output its contents to console, see in github.
package wekaExamples.loadDatasetExamples;
import weka.core.Instances;
import weka.core.converters.*;
import java.io.*;
/**
* Created by atilla.ozgur on 17.12.2014.
*/
public class LoadCsvExample {
public static void main(String[] args) {
System.out.println("loading training data");
Instances instances = null;
try {
String fileName = "./data/deneme1.csv";
CSVLoader loader = new CSVLoader();
loader.setSource(new File(fileName));
instances = loader.getDataSet();
} catch (Exception e) {
e.printStackTrace();
return;
}
System.out.println("training data loaded");
// Make the last attribute be the class
instances.setClassIndex(instances.numAttributes() - 1);
// Print header and instances.
System.out.println("\ndataset:\n");
System.out.println(instances);
}
}
Output is as following:
loading training data
training data loaded
dataset:
@relation deneme1
@attribute x numeric
@attribute y numeric
@data
1,2
2,3
1,4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With