1 | package de.ugoe.cs.cpdp.dataprocessing;
|
---|
2 |
|
---|
3 | import org.apache.commons.collections4.list.SetUniqueList;
|
---|
4 |
|
---|
5 | import weka.core.Attribute;
|
---|
6 | import weka.core.Instance;
|
---|
7 | import weka.core.Instances;
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * Logarithm transformation after Carmargo Cruz and Ochimizu: Towards Logistic Regression Models for Predicting Fault-prone Code across Software Projects.
|
---|
11 | * <br><br>
|
---|
12 | * Transform each attribute value x into log(x+1).
|
---|
13 | * @author Steffen Herbold
|
---|
14 | */
|
---|
15 | public class LogarithmTransform implements ISetWiseProcessingStrategy, IProcessesingStrategy {
|
---|
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 | * @see de.ugoe.cs.cpdp.dataprocessing.SetWiseProcessingStrategy#apply(weka.core.Instances, org.apache.commons.collections4.list.SetUniqueList)
|
---|
28 | */
|
---|
29 | @Override
|
---|
30 | public void apply(Instances testdata, SetUniqueList<Instances> traindataSet) {
|
---|
31 | final Attribute classAttribute = testdata.classAttribute();
|
---|
32 |
|
---|
33 | // preprocess testdata
|
---|
34 | for( int i=0 ; i<testdata.numInstances() ; i++ ) {
|
---|
35 | Instance instance = testdata.instance(i);
|
---|
36 | for( int j=0 ; j<testdata.numAttributes() ; j++ ) {
|
---|
37 | if( testdata.attribute(j)!=classAttribute ) {
|
---|
38 | instance.setValue(j, Math.log(1+instance.value(j)));
|
---|
39 | }
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | // preprocess training data
|
---|
44 | for( Instances traindata : traindataSet ) {
|
---|
45 | for( int i=0 ; i<traindata.numInstances() ; i++ ) {
|
---|
46 | Instance instance = traindata.instance(i);
|
---|
47 | for( int j=0 ; j<testdata.numAttributes() ; j++ ) {
|
---|
48 | if( testdata.attribute(j)!=classAttribute ) {
|
---|
49 | instance.setValue(j, Math.log(1+instance.value(j)));
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * @see de.ugoe.cs.cpdp.dataprocessing.ProcessesingStrategy#apply(weka.core.Instances, weka.core.Instances)
|
---|
58 | */
|
---|
59 | @Override
|
---|
60 | public void apply(Instances testdata, Instances traindata) {
|
---|
61 | final Attribute classAttribute = testdata.classAttribute();
|
---|
62 |
|
---|
63 | // preprocess testdata
|
---|
64 | for( int i=0 ; i<testdata.numInstances() ; i++ ) {
|
---|
65 | Instance instance = testdata.instance(i);
|
---|
66 | for( int j=0 ; j<testdata.numAttributes() ; j++ ) {
|
---|
67 | if( testdata.attribute(j)!=classAttribute ) {
|
---|
68 | instance.setValue(j, Math.log(1+instance.value(j)));
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | // preprocess training data
|
---|
74 | for( int i=0 ; i<traindata.numInstances() ; i++ ) {
|
---|
75 | Instance instance = traindata.instance(i);
|
---|
76 | for( int j=0 ; j<testdata.numAttributes() ; j++ ) {
|
---|
77 | if( testdata.attribute(j)!=classAttribute ) {
|
---|
78 | instance.setValue(j, Math.log(1+instance.value(j)));
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|