-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMMLRTest.java
More file actions
156 lines (127 loc) · 4.83 KB
/
Copy pathMMLRTest.java
File metadata and controls
156 lines (127 loc) · 4.83 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.Set;
import org.junit.Test;
public class MMLRTest {
@Test
public void testR1() throws Exception {
String string_json = Files.readString(Paths.get("./mml_test/LanguageTest/mml_LanguageTest1.json")); // no error
ReadJsonParameters parameters = new ReadJsonParameters(string_json);
parameters.read();
String filename = parameters.getFilemame();
String target_variable = parameters.getTargetVariable();
Set<Float> set_train_sizes = parameters.getTrainSizes();
Set<String> set_metrics = parameters.getMetrics();
Set<Integer> set_max_depth_values = parameters.getMaxDepthValues();
int repetition = parameters.getRepetition();
// set parameters to ConfigurationML
ConfigurationML configuration = new ConfigurationML();
configuration.setFilePath(filename);
configuration.setTarget(target_variable);
configuration.setMetrics(set_metrics);
for (float train_size : set_train_sizes) {
// Split dataset in train/test with traintestsplit script python
MLExecutor split = null;
configuration.setTrainSize(train_size);
split = new TrainTestSplit(configuration);
split.generateCode();
split.run();
for (int max_depth : set_max_depth_values) {
configuration.setMaxDepth(max_depth);
for(int i=0; i<repetition; i++){
MLExecutor ex = new RLanguageMLExecutor(configuration);
ex.generateCode();
MLResult result = ex.run();
try {
assertTrue(result.getStringResult().contains("accuracy"));
}
catch (AssertionError e) {
fail("not the good scoring");
}
}
}
}
}
@Test
public void testR2() throws Exception {
String string_json = Files.readString(Paths.get("./mml_test/LanguageTest/mml_LanguageTest2.json")); // colonne nom non valide
ReadJsonParameters parameters = new ReadJsonParameters(string_json);
parameters.read();
String filename = parameters.getFilemame();
String target_variable = parameters.getTargetVariable();
Set<Float> set_train_sizes = parameters.getTrainSizes();
Set<String> set_metrics = parameters.getMetrics();
Set<Integer> set_max_depth_values = parameters.getMaxDepthValues();
int repetition = parameters.getRepetition();
// set parameters to ConfigurationML
ConfigurationML configuration = new ConfigurationML();
configuration.setFilePath(filename);
configuration.setTarget(target_variable);
configuration.setMetrics(set_metrics);
for (float train_size : set_train_sizes) {
// Split dataset in train/test with traintestsplit script python
MLExecutor split = null;
configuration.setTrainSize(train_size);
split = new TrainTestSplit(configuration);
split.generateCode();
split.run();
for (int max_depth : set_max_depth_values) {
configuration.setMaxDepth(max_depth);
for(int i=0; i<repetition; i++){
MLExecutor ex = new RLanguageMLExecutor(configuration);
ex.generateCode();
MLResult result = ex.run();
if (result.getStringResult().contains("colonnes non définies")) {
assertTrue(true);
}
else {
fail("Il n'y a pas d'erreur renvoyée par R");
}
}
}
}
}
@Test
public void testR3() throws Exception {
String string_json = Files.readString(Paths.get("./mml_test/LanguageTest/mml_LanguageTest3.json")); // no error & test autre dataset
ReadJsonParameters parameters = new ReadJsonParameters(string_json);
parameters.read();
String filename = parameters.getFilemame();
String target_variable = parameters.getTargetVariable();
Set<Float> set_train_sizes = parameters.getTrainSizes();
Set<String> set_metrics = parameters.getMetrics();
Set<Integer> set_max_depth_values = parameters.getMaxDepthValues();
int repetition = parameters.getRepetition();
// set parameters to ConfigurationML
ConfigurationML configuration = new ConfigurationML();
configuration.setFilePath(filename);
configuration.setTarget(target_variable);
configuration.setMetrics(set_metrics);
for (float train_size : set_train_sizes) {
// Split dataset in train/test with traintestsplit script python
MLExecutor split = null;
configuration.setTrainSize(train_size);
split = new TrainTestSplit(configuration);
split.generateCode();
split.run();
for (int max_depth : set_max_depth_values) {
configuration.setMaxDepth(max_depth);
for(int i=0; i<repetition; i++){
MLExecutor ex = new RLanguageMLExecutor(configuration);
ex.generateCode();
MLResult result = ex.run();
try {
assertTrue(result.getStringResult().contains("accuracy"));
}
catch (AssertionError e) {
fail("not the good scoring");
}
}
}
}
}
}