[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 2002 University of Waikato |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | package weka.classifiers.meta; |
---|
| 22 | |
---|
| 23 | import weka.classifiers.AbstractClassifierTest; |
---|
| 24 | import weka.classifiers.Classifier; |
---|
| 25 | import weka.classifiers.CostMatrix; |
---|
| 26 | |
---|
| 27 | import java.io.InputStreamReader; |
---|
| 28 | |
---|
| 29 | import junit.framework.Test; |
---|
| 30 | import junit.framework.TestSuite; |
---|
| 31 | |
---|
| 32 | /** |
---|
| 33 | * Tests CostSensitiveClassifier. Run from the command line with:<p> |
---|
| 34 | * java weka.classifiers.meta.CostSensitiveClassifierTest |
---|
| 35 | * |
---|
| 36 | * @author <a href="mailto:eibe@cs.waikato.ac.nz">Eibe Frank</a> |
---|
| 37 | * @version $Revision: 1.5 $ |
---|
| 38 | */ |
---|
| 39 | public class CostSensitiveClassifierTest extends AbstractClassifierTest { |
---|
| 40 | |
---|
| 41 | public CostSensitiveClassifierTest(String name) { |
---|
| 42 | super(name); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | /** |
---|
| 46 | * Called by JUnit before each test method. This implementation creates |
---|
| 47 | * the default classifier to test and loads a test set of Instances. |
---|
| 48 | * |
---|
| 49 | * @exception Exception if an error occurs reading the example instances. |
---|
| 50 | */ |
---|
| 51 | protected void setUp() throws Exception { |
---|
| 52 | super.setUp(); |
---|
| 53 | |
---|
| 54 | // can handle only as much classes as there are in the CostMatrix! |
---|
| 55 | m_NClasses = ((CostSensitiveClassifier) getClassifier()).getCostMatrix().numRows(); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | /** Creates a default CostSensitiveClassifier */ |
---|
| 59 | public Classifier getClassifier() { |
---|
| 60 | |
---|
| 61 | CostSensitiveClassifier cl = new CostSensitiveClassifier(); |
---|
| 62 | |
---|
| 63 | // load costmatrix |
---|
| 64 | try { |
---|
| 65 | cl.setCostMatrix( |
---|
| 66 | new CostMatrix( |
---|
| 67 | new InputStreamReader(ClassLoader.getSystemResourceAsStream( |
---|
| 68 | "weka/classifiers/data/ClassifierTest.cost")))); |
---|
| 69 | } |
---|
| 70 | catch (Exception e) { |
---|
| 71 | e.printStackTrace(); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | return cl; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | public static Test suite() { |
---|
| 78 | return new TestSuite(CostSensitiveClassifierTest.class); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | public static void main(String[] args){ |
---|
| 82 | junit.textui.TestRunner.run(suite()); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | } |
---|