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.filters.supervised.instance; |
---|
22 | |
---|
23 | import weka.core.Instances; |
---|
24 | import weka.core.TestInstances; |
---|
25 | import weka.filters.AbstractFilterTest; |
---|
26 | import weka.filters.Filter; |
---|
27 | |
---|
28 | import junit.framework.Test; |
---|
29 | import junit.framework.TestSuite; |
---|
30 | |
---|
31 | /** |
---|
32 | * Tests SMOTE. Run from the command line with: <p/> |
---|
33 | * java weka.filters.supervised.instance.SMOTETest |
---|
34 | * |
---|
35 | * @author fracpete (FracPete at waikato dot ac dot nz) |
---|
36 | * @version $Revision: 4556 $ |
---|
37 | */ |
---|
38 | public class SMOTETest |
---|
39 | extends AbstractFilterTest { |
---|
40 | |
---|
41 | /** |
---|
42 | * Initializes the test. |
---|
43 | * |
---|
44 | * @param name the name of the test |
---|
45 | */ |
---|
46 | public SMOTETest(String name) { |
---|
47 | super(name); |
---|
48 | } |
---|
49 | |
---|
50 | /** |
---|
51 | * Need to set the class index |
---|
52 | * |
---|
53 | * @throws Exception if setup fails |
---|
54 | */ |
---|
55 | protected void setUp() throws Exception { |
---|
56 | super.setUp(); |
---|
57 | m_Instances.setClassIndex(1); |
---|
58 | } |
---|
59 | |
---|
60 | /** |
---|
61 | * returns data generated for the FilteredClassifier test |
---|
62 | * |
---|
63 | * @return the dataset for the FilteredClassifier |
---|
64 | * @throws Exception if generation of data fails |
---|
65 | */ |
---|
66 | protected Instances getFilteredClassifierData() throws Exception { |
---|
67 | TestInstances test; |
---|
68 | Instances result; |
---|
69 | |
---|
70 | // NB: in order to make sure that the classifier can handle the data, |
---|
71 | // we're using the classifier's capabilities to generate the data. |
---|
72 | test = TestInstances.forCapabilities( |
---|
73 | m_FilteredClassifier.getClassifier().getCapabilities()); |
---|
74 | test.setNumInstances(40); |
---|
75 | test.setClassIndex(TestInstances.CLASS_IS_LAST); |
---|
76 | |
---|
77 | result = test.generate(); |
---|
78 | |
---|
79 | return result; |
---|
80 | } |
---|
81 | |
---|
82 | /** |
---|
83 | * Creates a default SMOTE |
---|
84 | * |
---|
85 | * @return the default filter |
---|
86 | */ |
---|
87 | public Filter getFilter() { |
---|
88 | SMOTE f = new SMOTE(); |
---|
89 | return f; |
---|
90 | } |
---|
91 | |
---|
92 | /** |
---|
93 | * Returns a test suite. |
---|
94 | * |
---|
95 | * @return the test suite |
---|
96 | */ |
---|
97 | public static Test suite() { |
---|
98 | return new TestSuite(SMOTETest.class); |
---|
99 | } |
---|
100 | |
---|
101 | /** |
---|
102 | * Runs the test from commandline. |
---|
103 | * |
---|
104 | * @param args ignored |
---|
105 | */ |
---|
106 | public static void main(String[] args){ |
---|
107 | junit.textui.TestRunner.run(suite()); |
---|
108 | } |
---|
109 | } |
---|