-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,25 +5,31 @@ | |
import weka.filters.Filter; | ||
import weka.filters.supervised.instance.SpreadSubsample; | ||
|
||
/** | ||
* Extended class for bagging. Important that for every training set the majority class must be subsampled to the | ||
* minority class. | ||
* | ||
* @author <a href="mailto:[email protected]">Max Schubach</a> | ||
* | ||
*/ | ||
public class GWAVABagging extends Bagging { | ||
|
||
/** | ||
* for serialization | ||
*/ | ||
private static final long serialVersionUID = -3101726478201686871L; | ||
|
||
|
||
|
||
@Override | ||
protected synchronized Instances getTrainingSet(int iteration) throws Exception { | ||
Instances bagData = super.getTrainingSet(iteration); | ||
Instances bagData = super.getTrainingSet(iteration); | ||
|
||
SpreadSubsample subsample = new SpreadSubsample(); | ||
|
||
subsample.setRandomSeed(m_Seed); | ||
subsample.setDistributionSpread(1); | ||
subsample.setInputFormat(bagData); | ||
return Filter.useFilter(bagData, subsample); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
package weka.classifiers.trees; | ||
|
||
import weka.classifiers.trees.RandomForest; | ||
import weka.core.Instances; | ||
import weka.filters.Filter; | ||
import weka.filters.supervised.instance.SpreadSubsample; | ||
|
||
/** | ||
* The GWAVA random forest. Important that for every training set the majority class must be subsampled to the minority | ||
* class. | ||
* | ||
* @author <a href="mailto:[email protected]">Max Schubach</a> | ||
* | ||
*/ | ||
public class GWAVARandomForest extends RandomForest { | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,13 @@ | |
import weka.classifiers.trees.J48; | ||
import weka.core.Instances; | ||
|
||
/** | ||
* | ||
* test class for {@link GWAVABagging} | ||
* | ||
* @author <a href="mailto:[email protected]">Max Schubach</a> | ||
* | ||
*/ | ||
public class GWAVABaggingTest { | ||
|
||
private static Instances data; | ||
|
@@ -25,6 +32,11 @@ public class GWAVABaggingTest { | |
private static int seed = 42; | ||
private int folds = 10; | ||
|
||
/** | ||
* set up | ||
* | ||
* @throws Exception | ||
*/ | ||
@Before | ||
public void setUp() throws Exception { | ||
File file = new File(Resources.getResource(diabetesFile).getPath()); | ||
|
@@ -38,6 +50,11 @@ public void setUp() throws Exception { | |
randData.randomize(rand); | ||
} | ||
|
||
/** | ||
* test the tree | ||
* | ||
* @throws Exception | ||
*/ | ||
@Test | ||
public void classifyJ48Test() throws Exception { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,13 @@ | |
import weka.classifiers.Evaluation; | ||
import weka.core.Instances; | ||
|
||
/** | ||
* | ||
* test class for {@link GWAVARandomForest} | ||
* | ||
* @author <a href="mailto:[email protected]">Max Schubach</a> | ||
* | ||
*/ | ||
public class GWAVARandomForestTest { | ||
|
||
private Instances randDiabetesData; | ||
|
@@ -30,6 +37,12 @@ public class GWAVARandomForestTest { | |
private int seed = 42; | ||
private int folds = 10; | ||
|
||
/** | ||
* | ||
* setup (load data etc.) | ||
* | ||
* @throws Exception | ||
*/ | ||
@Before | ||
public void setUp() throws Exception { | ||
File file = new File(Resources.getResource(diabetesFile).getPath()); | ||
|
@@ -60,6 +73,11 @@ public void setUp() throws Exception { | |
randGeneratedImbalancedData.randomize(rand); | ||
} | ||
|
||
/** | ||
* test GWAVA vs tree | ||
* | ||
* @throws Exception | ||
*/ | ||
@Test | ||
public void classifyJ48Test() throws Exception { | ||
|
||
|
@@ -69,7 +87,7 @@ public void classifyJ48Test() throws Exception { | |
eval.crossValidateModel(gwava, randDiabetesData, folds, new Random(seed)); | ||
|
||
double prcGWAVA = eval.areaUnderPRC(1); | ||
double rocGWAVA= eval.areaUnderROC(1); | ||
double rocGWAVA = eval.areaUnderROC(1); | ||
|
||
eval = new Evaluation(randDiabetesData); | ||
eval.crossValidateModel(new J48(), randDiabetesData, folds, new Random(seed)); | ||
|
@@ -80,6 +98,11 @@ public void classifyJ48Test() throws Exception { | |
assertThat(rocGWAVA, Matchers.greaterThan(rocJ48)); | ||
} | ||
|
||
/** | ||
* test gwava vs tree bin data | ||
* | ||
* @throws Exception | ||
*/ | ||
@Test | ||
public void classifyRFRandomBinDataTest() throws Exception { | ||
|
||
|
@@ -89,17 +112,22 @@ public void classifyRFRandomBinDataTest() throws Exception { | |
|
||
Evaluation eval = new Evaluation(randGeneratedImbalancedBinData); | ||
eval.crossValidateModel(gwava, randGeneratedImbalancedBinData, folds, new Random(seed)); | ||
double prcHyperSMURF = eval.areaUnderPRC(1); | ||
double rocHyperSMURF = eval.areaUnderROC(1); | ||
double prcGWAVA = eval.areaUnderPRC(1); | ||
double rocGWAVA = eval.areaUnderROC(1); | ||
eval = new Evaluation(randGeneratedImbalancedBinData); | ||
eval.crossValidateModel(new J48(), randGeneratedImbalancedBinData, folds, new Random(seed)); | ||
double prcJ48 = eval.areaUnderPRC(1); | ||
double rocJ48 = eval.areaUnderROC(1); | ||
|
||
assertThat(prcHyperSMURF, Matchers.greaterThan(prcJ48)); | ||
assertThat(rocHyperSMURF, Matchers.greaterThan(rocJ48)); | ||
assertThat(prcGWAVA, Matchers.greaterThan(prcJ48)); | ||
assertThat(rocGWAVA, Matchers.greaterThan(rocJ48)); | ||
} | ||
|
||
/** | ||
* test gwava vst tree using random data | ||
* | ||
* @throws Exception | ||
*/ | ||
@Test | ||
public void classifyRFRandomDataTest() throws Exception { | ||
|
||
|