[mlpack-svn] r15512 - mlpack/conf/jenkins-conf/benchmark/methods/weka/src
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Jul 19 15:08:23 EDT 2013
Author: marcus
Date: Fri Jul 19 15:08:23 2013
New Revision: 15512
Log:
The weka NBC class cannot handle numeric classes, so we had to transform the dataset.
Modified:
mlpack/conf/jenkins-conf/benchmark/methods/weka/src/NBC.java
Modified: mlpack/conf/jenkins-conf/benchmark/methods/weka/src/NBC.java
==============================================================================
--- mlpack/conf/jenkins-conf/benchmark/methods/weka/src/NBC.java (original)
+++ mlpack/conf/jenkins-conf/benchmark/methods/weka/src/NBC.java Fri Jul 19 15:08:23 2013
@@ -10,6 +10,8 @@
import weka.core.Instances;
import weka.core.Utils;
import weka.core.converters.ConverterUtils.DataSource;
+import weka.filters.Filter;
+import weka.filters.unsupervised.attribute.NumericToNominal;
/**
* This class use the weka libary to implement Naive Bayes Classifier.
@@ -25,19 +27,30 @@
+ "-t [string] A file containing the training set.");
public static void main(String args[]) {
- Timers timer = new Timers();
+ Timers timer = new Timers();
try {
// Get the data set path.
String trainFile = Utils.getOption('t', args);
String testFile = Utils.getOption('T', args);
if (trainFile.length() == 0 || testFile.length() == 0)
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException();
// Load train and test dataset.
DataSource source = new DataSource(trainFile);
Instances trainData = source.getDataSet();
+
+ // Transform numeric class to nominal class because the
+ // classifier cannot handle numeric classes.
+ NumericToNominal nm = new NumericToNominal();
+ String[] options = new String[2];
+ options[0] = "-R";
+ options[1] = "last"; //set the attributes from indices 1 to 2 as
+ nm.setOptions(options);
+ nm.setInputFormat(trainData);
+ trainData = Filter.useFilter(trainData, nm);
+
// Use the last row of the training data as the labels.
- trainData.setClassIndex((trainData.numAttributes() - 1));
+ trainData.setClassIndex((trainData.numAttributes() - 1));
source = new DataSource(testFile);
Instances testData = source.getDataSet();
More information about the mlpack-svn
mailing list