source: trunk/CrossPare/src/de/ugoe/cs/cpdp/dataprocessing/Resampling.java @ 40

Last change on this file since 40 was 38, checked in by sherbold, 9 years ago
  • added Oversampling and Resampling processors
  • fixed bug in ZScoreNormalizations
  • added new load for the Audi data set that is based on changes
  • minor changes to remove warnings
  • Property svn:mime-type set to text/plain
File size: 1.6 KB
Line 
1package de.ugoe.cs.cpdp.dataprocessing;
2
3import org.apache.commons.collections4.list.SetUniqueList;
4
5import weka.core.Instances;
6import weka.filters.Filter;
7import weka.filters.supervised.instance.Resample;
8
9/**
10 * Resamples the data with WEKA {@link Resample} to have a uniform distribution among all classes.   
11 * @author Steffen Herbold
12 */
13public class Resampling implements IProcessesingStrategy,
14                ISetWiseProcessingStrategy {
15
16       
17        /**
18         * Does not have parameters. String is ignored.
19         * @param parameters ignored
20         */
21        @Override
22        public void setParameter(String parameters) {
23                // dummy
24        }
25
26        /*
27         * (non-Javadoc)
28         * @see de.ugoe.cs.cpdp.dataprocessing.ISetWiseProcessingStrategy#apply(weka.core.Instances, org.apache.commons.collections4.list.SetUniqueList)
29         */
30        @Override
31        public void apply(Instances testdata, SetUniqueList<Instances> traindataSet) {
32                for( Instances traindata : traindataSet ) {
33                        apply(testdata, traindata);
34                }
35        }
36
37        /*
38         * (non-Javadoc)
39         * @see de.ugoe.cs.cpdp.dataprocessing.IProcessesingStrategy#apply(weka.core.Instances, weka.core.Instances)
40         */
41        @Override
42        public void apply(Instances testdata, Instances traindata) {
43                Resample resample = new Resample();
44                resample.setSampleSizePercent(100);
45                resample.setBiasToUniformClass(1.0);
46               
47                Instances traindataSample;
48                try {
49                        resample.setInputFormat(traindata);
50                        traindataSample = Filter.useFilter(traindata, resample);
51                } catch (Exception e) {
52                        throw new RuntimeException(e);
53                }
54                traindata.clear();
55                for( int i=0 ; i<traindataSample.size() ; i++ ) {
56                        traindata.add(traindataSample.get(i));
57                }
58        }
59
60}
Note: See TracBrowser for help on using the repository browser.