/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* * TrainTestExperiment.java * Copyright (C) 2009-2010 Aristotle University of Thessaloniki, Thessaloniki, Greece */ package mulan.examples; import mulan.classifier.transformation.BinaryRelevance; import mulan.data.MultiLabelInstances; import mulan.evaluation.Evaluation; import mulan.evaluation.Evaluator; import weka.classifiers.Classifier; import weka.classifiers.bayes.NaiveBayes; import weka.core.Instances; import weka.core.Utils; import weka.filters.Filter; import weka.filters.unsupervised.instance.RemovePercentage; /** * Class demonstrating a simple train/test evaluation experiment * * @author Grigorios Tsoumakas * @version 2010.12.27 */ public class TrainTestExperiment { public static void main(String[] args) { try { String path = Utils.getOption("path", args); // e.g. -path dataset/ String filestem = Utils.getOption("filestem", args); // e.g. -filestem emotions String percentage = Utils.getOption("percentage", args); // e.g. -percentage 50 (for 50%) System.out.println("Loading the dataset"); MultiLabelInstances mlDataSet = new MultiLabelInstances(path + filestem + ".arff", path + filestem + ".xml"); // split the data set into train and test Instances dataSet = mlDataSet.getDataSet(); RemovePercentage rmvp = new RemovePercentage(); rmvp.setInvertSelection(true); rmvp.setPercentage(Double.parseDouble(percentage)); rmvp.setInputFormat(dataSet); Instances trainDataSet = Filter.useFilter(dataSet, rmvp); rmvp = new RemovePercentage(); rmvp.setPercentage(Double.parseDouble(percentage)); rmvp.setInputFormat(dataSet); Instances testDataSet = Filter.useFilter(dataSet, rmvp); MultiLabelInstances train = new MultiLabelInstances(trainDataSet, path + filestem + ".xml"); MultiLabelInstances test = new MultiLabelInstances(testDataSet, path + filestem + ".xml"); Evaluator eval = new Evaluator(); Evaluation results; Classifier brClassifier = new NaiveBayes(); BinaryRelevance br = new BinaryRelevance(brClassifier); br.setDebug(true); br.build(train); results = eval.evaluate(br, test); System.out.println(results); } catch (Exception e) { e.printStackTrace(); } } }