📄 wekaassociationlearner.java
字号:
/* * YALE - Yet Another Learning Environment * Copyright (C) 2002, 2003 * Simon Fischer, Ralf Klinkenberg, Ingo Mierswa, * Katharina Morik, Oliver Ritthoff * Artificial Intelligence Unit * Computer Science Department * University of Dortmund * 44221 Dortmund, Germany * email: yale@ls8.cs.uni-dortmund.de * web: http://yale.cs.uni-dortmund.de/ * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. */package edu.udo.cs.yale.operator.learner;import edu.udo.cs.yale.operator.parameter.*;import edu.udo.cs.yale.operator.Operator;import edu.udo.cs.yale.operator.IOObject;import edu.udo.cs.yale.operator.ResultObjectAdapter;import edu.udo.cs.yale.operator.OperatorException;import edu.udo.cs.yale.operator.UserError;import edu.udo.cs.yale.example.Example;import edu.udo.cs.yale.example.ExampleReader;import edu.udo.cs.yale.example.ExampleSet;import edu.udo.cs.yale.tools.Ontology;import edu.udo.cs.yale.tools.LogService;import edu.udo.cs.yale.tools.WekaTools;import weka.associations.Associator;import weka.core.Instances;import java.util.List;import java.util.Iterator;/** This class builds a Weka Associator. The operator returns a result object * containing the rules found by the association learner. In contrast to models * generated by normal learners, the association rules cannot be applied to * an example set. Hence, there is no way to evaluate the performance of association * rules yet. * * @yale.xmlclass WekaAssociator * @version $Id: WekaAssociationLearner.java,v 2.1 2003/08/06 11:52:57 fischer Exp $ */public class WekaAssociationLearner extends Operator { public static final String[] WEKA_CLASSIFIERS = WekaTools.getWekaClasses(weka.associations.Associator.class, "weka.associations"); public Class[] getInputClasses() { return new Class[] { ExampleSet.class }; } public Class[] getOutputClasses() { return new Class[] { WekaAssociator.class }; } public static class WekaAssociator extends ResultObjectAdapter { private Associator associator; public WekaAssociator(Associator associator) { this.associator = associator; } public String toString() { return associator.toString(); } } public IOObject[] apply() throws OperatorException { ExampleSet exampleSet = (ExampleSet)getInput(ExampleSet.class); String operatorName = getParameterAsString("weka_associator_name"); List wekaParameters = getParameterList("weka_parameters"); String[] parameters = WekaTools.getWekaParameters(wekaParameters); Associator associator = null; try { associator = Associator.forName(operatorName, parameters); } catch (Exception e) { throw new UserError(this, e, 904, new Object[] { operatorName, e}); } LogService.logMessage(getName() + ": Converting to Weka instances.", LogService.MINIMUM); Instances instances = WekaTools.toWekaInstances(exampleSet, "TempInstances"); try { LogService.logMessage(getName() + ": Building Weka associator.", LogService.MINIMUM); associator.buildAssociations(instances); } catch (Exception e) { throw new UserError(this, e, 905, new Object[] {operatorName, e}); } return new IOObject[] { new WekaAssociator(associator) }; } public List getParameterTypes() { List types = super.getParameterTypes(); types.add(new ParameterTypeStringCategory("weka_associator_name", "The fully qualified classname of the weka associator.", WEKA_CLASSIFIERS)); types.add(new ParameterTypeList("weka_parameters", "Parameters for the Weka associator as described in the Weka manual.", new ParameterTypeString(null, null))); return types; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -