Java tutorial
/* * 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 3 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, see <http://www.gnu.org/licenses/>. */ /** * WekaEvaluationToThresholdCurve.java * Copyright (C) 2014 University of Waikato, Hamilton, New Zealand */ package adams.data.conversion; import weka.classifiers.Evaluation; import weka.classifiers.evaluation.ThresholdCurve; import weka.core.Instances; import adams.core.Index; /** <!-- globalinfo-start --> * Generates threshold-curve data from a WEKA Evaluation object. * <br><br> <!-- globalinfo-end --> * <!-- options-start --> * <pre>-logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel) * The logging level for outputting errors and debugging output. * default: WARNING * </pre> * * <pre>-index <adams.core.Index> (property: classLabelIndex) * The index of the class label to use for generating the data. * default: first * example: An index is a number starting with 1; the following placeholders can be used as well: first, second, third, last_2, last_1, last * </pre> * <!-- options-end --> * * @author fracpete (fracpete at waikato dot ac dot nz) * @version $Revision$ */ public class WekaEvaluationToThresholdCurve extends AbstractConversion { /** for serialization. */ private static final long serialVersionUID = -3340269698168769770L; /** the class label index. */ protected Index m_ClassLabelIndex; /** * Returns a string describing the object. * * @return a description suitable for displaying in the gui */ @Override public String globalInfo() { return "Generates threshold-curve data from a WEKA Evaluation object."; } /** * Adds options to the internal list of options. */ @Override public void defineOptions() { super.defineOptions(); m_OptionManager.add("index", "classLabelIndex", new Index(Index.FIRST)); } /** * Initializes the members. */ @Override protected void initialize() { super.initialize(); m_ClassLabelIndex = new Index("first"); } /** * Sets the class label index (1-based index). * * @param value the index */ public void setClassLabelIndex(Index value) { m_ClassLabelIndex = value; reset(); } /** * Returns the class label index (1-based index). * * @return the index */ public Index getClassLabelIndex() { return m_ClassLabelIndex; } /** * Returns the tip text for this property. * * @return tip text for this property suitable for * displaying in the GUI or for listing the options. */ public String classLabelIndexTipText() { return "The index of the class label to use for generating the data."; } /** * Returns the class that is accepted as input. * * @return the class */ @Override public Class accepts() { return Evaluation.class; } /** * Returns the class that is generated as output. * * @return the class */ @Override public Class generates() { return Instances.class; } /** * Performs the actual conversion. * * @return the converted data * @throws Exception if something goes wrong with the conversion */ @Override protected Object doConvert() throws Exception { Evaluation eval; ThresholdCurve curve; Instances cost; eval = (Evaluation) m_Input; m_ClassLabelIndex.setMax(eval.getHeader().classAttribute().numValues()); curve = new ThresholdCurve(); cost = curve.getCurve(eval.predictions(), m_ClassLabelIndex.getIntIndex()); return cost; } }