- 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/AttributeRemoval.java
r2 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 … … 6 20 7 21 /** 8 * Removes an attributes from all data sets using their name. 22 * Removes an attributes from all data sets using their name. 23 * 9 24 * @author Steffen Herbold 10 25 */ 11 26 public class AttributeRemoval implements ISetWiseProcessingStrategy, IProcessesingStrategy { 12 27 13 /** 14 * names of the attributes to be removed (determined by {@link #setParameter(String)}) 15 */ 16 private String[] attributeNames = new String[]{}; 17 18 /** 19 * Sets that attributes that will be removed. The string contains the blank-separated names of the attributes to be removed. 20 * <br><br> 21 * Note, that removal of attributes with blanks is currently not supported! 22 * @param parameters string with the blank-separated attribute names 23 */ 24 @Override 25 public void setParameter(String parameters) { 26 if( parameters!=null ) { 27 attributeNames = parameters.split(" "); 28 } 29 } 28 /** 29 * names of the attributes to be removed (determined by {@link #setParameter(String)}) 30 */ 31 private String[] attributeNames = new String[] { }; 30 32 31 /** 32 * @see de.ugoe.cs.cpdp.dataprocessing.SetWiseProcessingStrategy#apply(weka.core.Instances, org.apache.commons.collections4.list.SetUniqueList) 33 */ 34 @Override 35 public void apply(Instances testdata, SetUniqueList<Instances> traindataSet) { 36 for( String attributeName : attributeNames ) { 37 for( int i=0 ; i<testdata.numAttributes() ; i++ ) { 38 if( attributeName.equals(testdata.attribute(i).name()) ) { 39 testdata.deleteAttributeAt(i); 40 for( Instances traindata : traindataSet ) { 41 traindata.deleteAttributeAt(i); 42 } 43 } 44 } 45 } 46 } 33 /** 34 * Sets that attributes that will be removed. The string contains the blank-separated names of 35 * the attributes to be removed. <br> 36 * <br> 37 * Note, that removal of attributes with blanks is currently not supported! 38 * 39 * @param parameters 40 * string with the blank-separated attribute names 41 */ 42 @Override 43 public void setParameter(String parameters) { 44 if (parameters != null) { 45 attributeNames = parameters.split(" "); 46 } 47 } 47 48 48 /** 49 * @see de.ugoe.cs.cpdp.dataprocessing.ProcessesingStrategy#apply(weka.core.Instances, weka.core.Instances) 50 */ 51 @Override 52 public void apply(Instances testdata, Instances traindata) { 53 for( String attributeName : attributeNames ) { 54 for( int i=0 ; i<testdata.numAttributes() ; i++ ) { 55 if( attributeName.equals(testdata.attribute(i).name()) ) { 56 testdata.deleteAttributeAt(i); 57 traindata.deleteAttributeAt(i); 58 } 59 } 60 } 61 } 49 /** 50 * @see de.ugoe.cs.cpdp.dataprocessing.SetWiseProcessingStrategy#apply(weka.core.Instances, 51 * org.apache.commons.collections4.list.SetUniqueList) 52 */ 53 @Override 54 public void apply(Instances testdata, SetUniqueList<Instances> traindataSet) { 55 for (String attributeName : attributeNames) { 56 for (int i = 0; i < testdata.numAttributes(); i++) { 57 if (attributeName.equals(testdata.attribute(i).name())) { 58 testdata.deleteAttributeAt(i); 59 for (Instances traindata : traindataSet) { 60 traindata.deleteAttributeAt(i); 61 } 62 } 63 } 64 } 65 } 66 67 /** 68 * @see de.ugoe.cs.cpdp.dataprocessing.ProcessesingStrategy#apply(weka.core.Instances, 69 * weka.core.Instances) 70 */ 71 @Override 72 public void apply(Instances testdata, Instances traindata) { 73 for (String attributeName : attributeNames) { 74 for (int i = 0; i < testdata.numAttributes(); i++) { 75 if (attributeName.equals(testdata.attribute(i).name())) { 76 testdata.deleteAttributeAt(i); 77 traindata.deleteAttributeAt(i); 78 } 79 } 80 } 81 } 62 82 }
Note: See TracChangeset
for help on using the changeset viewer.