- Timestamp:
- 09/24/15 10:59:05 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CrossPare/src/de/ugoe/cs/cpdp/dataprocessing/Resampling.java
r38 r41 1 // Copyright 2015 Georg-August-Universität Göttingen, Germany 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 1 15 package de.ugoe.cs.cpdp.dataprocessing; 2 16 … … 8 22 9 23 /** 10 * Resamples the data with WEKA {@link Resample} to have a uniform distribution among all classes. 24 * Resamples the data with WEKA {@link Resample} to have a uniform distribution among all classes. 25 * 11 26 * @author Steffen Herbold 12 27 */ 13 public class Resampling implements IProcessesingStrategy, 14 ISetWiseProcessingStrategy { 28 public class Resampling implements IProcessesingStrategy, ISetWiseProcessingStrategy { 15 29 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 } 30 /** 31 * Does not have parameters. String is ignored. 32 * 33 * @param parameters 34 * ignored 35 */ 36 @Override 37 public void setParameter(String parameters) { 38 // dummy 39 } 25 40 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 } 41 /* 42 * (non-Javadoc) 43 * 44 * @see de.ugoe.cs.cpdp.dataprocessing.ISetWiseProcessingStrategy#apply(weka.core.Instances, 45 * org.apache.commons.collections4.list.SetUniqueList) 46 */ 47 @Override 48 public void apply(Instances testdata, SetUniqueList<Instances> traindataSet) { 49 for (Instances traindata : traindataSet) { 50 apply(testdata, traindata); 51 } 52 } 36 53 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 } 54 /* 55 * (non-Javadoc) 56 * 57 * @see de.ugoe.cs.cpdp.dataprocessing.IProcessesingStrategy#apply(weka.core.Instances, 58 * weka.core.Instances) 59 */ 60 @Override 61 public void apply(Instances testdata, Instances traindata) { 62 Resample resample = new Resample(); 63 resample.setSampleSizePercent(100); 64 resample.setBiasToUniformClass(1.0); 65 66 Instances traindataSample; 67 try { 68 resample.setInputFormat(traindata); 69 traindataSample = Filter.useFilter(traindata, resample); 70 } 71 catch (Exception e) { 72 throw new RuntimeException(e); 73 } 74 traindata.clear(); 75 for (int i = 0; i < traindataSample.size(); i++) { 76 traindata.add(traindataSample.get(i)); 77 } 78 } 59 79 60 80 }
Note: See TracChangeset
for help on using the changeset viewer.