| [4] | 1 | /* |
|---|
| 2 | * This program is free software; you can redistribute it and/or modify |
|---|
| 3 | * it under the terms of the GNU General Public License as published by |
|---|
| 4 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 5 | * (at your option) any later version. |
|---|
| 6 | * |
|---|
| 7 | * This program is distributed in the hope that it will be useful, |
|---|
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 10 | * GNU General Public License for more details. |
|---|
| 11 | * |
|---|
| 12 | * You should have received a copy of the GNU General Public License |
|---|
| 13 | * along with this program; if not, write to the Free Software |
|---|
| 14 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 15 | */ |
|---|
| 16 | |
|---|
| 17 | /* |
|---|
| 18 | * Copyright (C) 2008 University of Waikato, Hamilton, New Zealand |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | package weka.attributeSelection; |
|---|
| 22 | |
|---|
| 23 | import weka.classifiers.CostMatrix; |
|---|
| 24 | |
|---|
| 25 | import java.io.InputStreamReader; |
|---|
| 26 | |
|---|
| 27 | import junit.framework.Test; |
|---|
| 28 | import junit.framework.TestSuite; |
|---|
| 29 | |
|---|
| 30 | /** |
|---|
| 31 | * Tests CostSensitiveSubsetEval. Run from the command line with:<p/> |
|---|
| 32 | * java weka.attributeSelection.CostSensitiveAttributeEvalTest |
|---|
| 33 | * |
|---|
| 34 | * @author Mark Hall (mhall{[at]}pentaho{[dot]}com |
|---|
| 35 | * @version $Revision: 5563 $ |
|---|
| 36 | */ |
|---|
| 37 | public class CostSensitiveSubsetEvalTest |
|---|
| 38 | extends AbstractEvaluatorTest { |
|---|
| 39 | |
|---|
| 40 | public CostSensitiveSubsetEvalTest(String name) { |
|---|
| 41 | super(name); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | /** |
|---|
| 45 | * Called by JUnit before each test method. This implementation creates |
|---|
| 46 | * the default evaluator to test and loads a test set of Instances. |
|---|
| 47 | * |
|---|
| 48 | * @exception Exception if an error occurs reading the example instances. |
|---|
| 49 | */ |
|---|
| 50 | protected void setUp() throws Exception { |
|---|
| 51 | super.setUp(); |
|---|
| 52 | |
|---|
| 53 | // can handle only as much classes as there are in the CostMatrix! |
|---|
| 54 | m_NClasses = ((CostSensitiveSubsetEval) getEvaluator()).getCostMatrix().numRows(); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | /** Creates a default BestFirst */ |
|---|
| 58 | public ASSearch getSearch() { |
|---|
| 59 | return new BestFirst(); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | /** Creates a default CostSensitiveSubsetEval */ |
|---|
| 63 | public ASEvaluation getEvaluator() { |
|---|
| 64 | CostSensitiveSubsetEval csse = new CostSensitiveSubsetEval(); |
|---|
| 65 | |
|---|
| 66 | // load cost matrix |
|---|
| 67 | try { |
|---|
| 68 | csse.setCostMatrix( |
|---|
| 69 | new CostMatrix( |
|---|
| 70 | new InputStreamReader(ClassLoader.getSystemResourceAsStream( |
|---|
| 71 | "weka/classifiers/data/ClassifierTest.cost")))); |
|---|
| 72 | } catch (Exception e) { |
|---|
| 73 | e.printStackTrace(); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | return csse; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | public static Test suite() { |
|---|
| 80 | return new TestSuite(CostSensitiveSubsetEvalTest.class); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | public static void main(String[] args){ |
|---|
| 84 | junit.textui.TestRunner.run(suite()); |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | } |
|---|