Menu

[572a65]: / src / junit / featureselection / TestLinearEnsemble.java  Maximize  Restore  History

Download this file

62 lines (46 with data), 1.8 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* %SVN.HEADER%
*/
package junit.featureselection;
import net.sf.javaml.core.Dataset;
import net.sf.javaml.core.DefaultDataset;
import net.sf.javaml.core.DenseInstance;
import net.sf.javaml.core.Instance;
import net.sf.javaml.featureselection.FeatureRanking;
import net.sf.javaml.featureselection.ensemble.LinearRankingEnsemble;
import net.sf.javaml.featureselection.ranking.RecursiveFeatureEliminationSVM;
import net.sf.javaml.sampling.Sampling;
import org.junit.Test;
import be.abeel.util.Pair;
/**
* Test-case for Linear ensemble feature selection
*
* @author Thomas Abeel
*
*/
public class TestLinearEnsemble {
@Test
public void testGreedyBackwardEliminationSynthetic() {
Dataset data = new DefaultDataset();
for (int i = 0; i < 100; i++) {
double[] vals = { i / 50,vary(1, 0), Math.random(), vary(5 * (i / 50), 1) };
Instance inst = new DenseInstance(vals, ""+(i / 50));
data.add(inst);
}
FeatureRanking[] ars = new FeatureRanking[10];
for (int i = 0; i < ars.length; i++)
ars[i] = new RecursiveFeatureEliminationSVM(1.0);
Pair<Dataset,Dataset>split=Sampling.SubSampling.sample(data,(int)(data.size()*0.5));
System.out.println("Training feature selection...");
FeatureRanking ens = new LinearRankingEnsemble(ars);
ens.build(split.x().copy());
for(int i=0;i<data.noAttributes();i++)
System.out.println(i+"\t"+ens.rank(i));
// System.out.println(ga.selectedAttributes());
// Assert.assertTrue(ga.selectedAttributes().contains(0));
// Assert.assertTrue(ga.selectedAttributes().contains(3));
}
private double vary(double i, double j) {
return i + j * Math.random();
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.