Commit 44a9b217 authored by Bruno López Trigo's avatar Bruno López Trigo

Versión completamente funcional, a falta de pasar batería de probas

parent 519e2bbb
......@@ -169,8 +169,33 @@ public class ClassifierManagerImpl implements ClassifierManager {
this.treeInterpreter = new TreeInterpreter(root);
return this.treeInterpreter.exploreAlternatives(instance, config, percentage / 100);
ArrayList<ArrayList<Classification>> classifications = new ArrayList();
ArrayList<Classification> solution = new ArrayList();
for(int i=1; i<percentage; i++){
classifications.add(this.treeInterpreter.exploreAlternatives(instance, config, ((double) i) / 100));
}
classifications.add(this.treeInterpreter.exploreAlternatives(instance, config, percentage / 100));
boolean found = false;
for(int i=0; i<classifications.size(); i++){
for(Classification c: classifications.get(i)){
for(Classification clasification: solution){
if(c.getConsequent().getId().equals(clasification.getConsequent().getId())){
found = true;
}
}
if(!found){
solution.add(c);
}
found = false;
}
}
return solution;
}
@Override
......
......@@ -71,6 +71,8 @@ public class MatrixBuilder {
this.sc.close();
m.setPrecision();
return m;
}
......@@ -121,6 +123,8 @@ public class MatrixBuilder {
}
}
m.setPrecision();
return m;
}
......
......@@ -92,7 +92,11 @@ public class DatasetManagerImpl implements DatasetManager {
File testFile;
Dataset dataset = null;
testFile = this.fmanager.getTest(token, name);
try {
testFile = this.fmanager.getTest(name);
} catch (NotFoundEx ex) {
testFile = this.fmanager.getTest(token, name);
}
dataset = buildDataset(name, testFile);
......
......@@ -26,17 +26,7 @@ public class ConfusionAnalyzer {
}
public double getGlobalPercentage(){
String line = this.sc.nextLine();
while (!line.startsWith("Correctly Classified Instances")) {
line = this.sc.nextLine();
}
this.sc.close();
return Double.parseDouble(line.split("\\s+")[4]);
return this.matrix.getPrecision();
}
public ArrayList<Integer> getWrongInstances(int i, int j){
......
......@@ -29,6 +29,14 @@ public class CategoricNode extends Node {
return null;
}
public boolean containsNotEqual(){
for(Map.Entry<String, Node> entry: this.children.entrySet()){
if(entry.getKey().startsWith("!="))
return true;
}
return false;
}
public HashMap<String, Node> getChildren() {
return children;
}
......
......@@ -6,6 +6,7 @@ import java.util.HashMap;
public class Matrix {
private ArrayList<ArrayList<Integer>> data;
private double precision;
private boolean adjMatrix[][];
private HashMap<Position, ArrayList<Integer>> confused;
......@@ -25,6 +26,25 @@ public class Matrix {
this.confused = new HashMap();
}
public void setPrecision(){
double sumDiagonal = 0;
double sumTotal = 0;
for(int i=0; i<this.data.size(); i++){
for(int j=0; j<this.data.size(); j++){
if (i==j)
sumDiagonal += this.data.get(i).get(j);
sumTotal += this.data.get(i).get(j);
}
}
this.precision = sumDiagonal / sumTotal * 100;
}
public double getPrecision() {
return precision;
}
public void addRow(ArrayList<Integer> row) {
if(this.adjMatrix == null)
......
......@@ -191,6 +191,20 @@ public class FileManager {
}
}
public String getTestLocation(String dataset) {
return BASE + dataset + "/" + dataset + "-test.arff";
}
public File getTest(String dataset) throws NotFoundEx {
File f = new File(BASE + dataset + "/" + dataset + "-test.arff");
if (f.exists()) {
return f;
} else {
throw new NotFoundEx("Test dataset not found");
}
}
public String getTestLocation(String token, String dataset) {
return BASE + "tmp/" + token + "/" + dataset + "/" + dataset + "-test.arff";
}
......
=== Run information ===
Scheme: trees.J48 -C 0.25 -M 2
Relation: BEER3
Instances: 400
Relation: BEER3-weka.filters.supervised.instance.StratifiedRemoveFolds-S0-V-N3-F1
Instances: 266
Attributes: 4
Color
Bitterness
......@@ -18,52 +18,47 @@ J48 pruned tree
Strength <= 0.07
| Color <= 17
| | Color <= 6
| | | Bitterness <= 26: 1.0 (50.0)
| | | Bitterness > 26: 3.0 (49.0)
| | Color > 6
| | | Strength <= 0.057: 2.0 (50.0/1.0)
| | | Strength > 0.057: 4.0 (2.0)
| | | Bitterness <= 25: 1.0 (33.0)
| | | Bitterness > 25: 3.0 (33.0)
| | Color > 6: 2.0 (34.0/2.0)
| Color > 17
| | Color <= 29: 7.0 (50.0/1.0)
| | Color > 29: 5.0 (51.0/1.0)
| | Color <= 29: 7.0 (33.0/1.0)
| | Color > 29: 5.0 (34.0/1.0)
Strength > 0.07
| Bitterness <= 48: 8.0 (50.0)
| Bitterness > 48
| | Strength <= 0.091: 4.0 (48.0/3.0)
| | Strength > 0.091
| | | Color <= 11
| | | | Color <= 8: 4.0 (2.0)
| | | | Color > 8: 6.0 (5.0/1.0)
| | | Color > 11: 6.0 (43.0)
| Color <= 25
| | Strength <= 0.091: 4.0 (34.0/3.0)
| | Strength > 0.091: 6.0 (32.0/1.0)
| Color > 25: 8.0 (33.0)
Number of Leaves : 11
Number of Leaves : 8
Size of the tree : 21
Size of the tree : 15
=== Summary ===
Correctly Classified Instances 380 95 %
Incorrectly Classified Instances 20 5 %
Kappa statistic 0.9429
K&B Relative Info Score 37623.8021 %
K&B Information Score 1128.7141 bits 2.8218 bits/instance
Class complexity | order 0 1200 bits 3 bits/instance
Class complexity | scheme 11862.1852 bits 29.6555 bits/instance
Complexity improvement (Sf) -10662.1852 bits -26.6555 bits/instance
Mean absolute error 0.0163
Root mean squared error 0.1083
Relative absolute error 7.4669 %
Root relative squared error 32.7442 %
Total Number of Instances 400
Correctly Classified Instances 252 94.7368 %
Incorrectly Classified Instances 14 5.2632 %
Kappa statistic 0.9398
K&B Relative Info Score 24933.4711 %
K&B Information Score 748.0041 bits 2.812 bits/instance
Class complexity | order 0 798.8128 bits 3.0031 bits/instance
Class complexity | scheme 10760.4703 bits 40.4529 bits/instance
Complexity improvement (Sf) -9961.6576 bits -37.4498 bits/instance
Mean absolute error 0.0175
Root mean squared error 0.112
Relative absolute error 7.9821 %
Root relative squared error 33.8482 %
Total Number of Instances 266
=== Confusion Matrix ===
a b c d e f g h <-- classified as
50 0 0 0 0 0 0 0 | a = 1.0
0 49 0 0 0 0 1 0 | b = 2.0
0 1 48 1 0 0 0 0 | c = 3.0
0 1 1 44 0 4 0 0 | d = 4.0
0 0 0 0 49 0 0 1 | e = 5.0
0 0 0 7 0 42 0 1 | f = 6.0
0 0 0 0 1 0 49 0 | g = 7.0
0 0 0 0 0 1 0 49 | h = 8.0
33 0 0 0 0 0 0 0 | a = 1.0
0 32 0 0 0 0 1 0 | b = 2.0
0 1 33 0 0 0 0 0 | c = 3.0
0 1 0 27 0 5 0 0 | d = 4.0
0 0 0 0 31 0 1 1 | e = 5.0
0 0 0 2 0 31 0 1 | f = 6.0
0 0 0 0 1 0 32 0 | g = 7.0
0 0 0 0 0 0 0 33 | h = 8.0
{
"data": [[50, 0, 0, 0, 0, 0, 0, 0], [0, 49, 0, 0, 0, 0, 1, 0], [0, 1, 48, 1, 0, 0, 0, 0], [0, 1, 1, 44, 0, 4, 0, 0], [0, 0, 0, 0, 49, 0, 0, 1], [0, 0, 0, 7, 0, 42, 0, 1], [0, 0, 0, 0, 1, 0, 49, 0], [0, 0, 0, 0, 0, 1, 0, 49]],
"adjMatrix": [[false, false, false, false, false, false, false, false], [false, false, false, false, false, false, true, false], [false, true, false, true, false, false, false, false], [false, true, true, false, false, true, false, false], [false, false, false, false, false, false, false, true], [false, false, false, true, false, false, false, true], [false, false, false, false, true, false, false, false], [false, false, false, false, false, true, false, false]]
"data" : [ [ 33, 0, 0, 0, 0, 0, 0, 0 ], [ 0, 32, 0, 0, 0, 0, 1, 0 ], [ 0, 1, 33, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 27, 0, 5, 0, 0 ], [ 0, 0, 0, 0, 31, 0, 1, 1 ], [ 0, 0, 0, 2, 0, 31, 0, 1 ], [ 0, 0, 0, 0, 1, 0, 32, 0 ], [ 0, 0, 0, 0, 0, 0, 0, 33 ] ],
"precision" : 94.73684210526315,
"adjMatrix" : [ [ false, false, false, false, false, false, false, false ], [ false, false, false, false, false, false, true, false ], [ false, true, false, false, false, false, false, false ], [ false, true, false, false, false, true, false, false ], [ false, false, false, false, false, false, true, true ], [ false, false, false, true, false, false, false, true ], [ false, false, false, false, true, false, false, false ], [ false, false, false, false, false, false, false, false ] ],
"confused" : { }
}
\ No newline at end of file
{
"data" : [ [ 17, 0, 0, 0, 0, 0, 0, 0 ], [ 0, 17, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 16, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 14, 0, 2, 0, 0 ], [ 0, 0, 0, 0, 17, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 16, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 17, 0 ], [ 0, 0, 0, 0, 0, 1, 0, 16 ] ],
"precision" : 97.01492537313433,
"adjMatrix" : null,
"confused" : {
"3:1" : [ 58 ],
"7:5" : [ 134 ],
"3:5" : [ 54, 65 ]
}
}
\ No newline at end of file
{
"data": [[50, 0, 0, 0, 0, 0, 0, 0], [0, 49, 0, 0, 0, 0, 1, 0], [0, 1, 49, 0, 0, 0, 0, 0], [0, 0, 0, 49, 0, 1, 0, 0], [0, 0, 0, 0, 50, 0, 0, 0], [0, 0, 0, 3, 0, 47, 0, 0], [0, 0, 0, 0, 1, 0, 49, 0], [0, 0, 0, 0, 0, 0, 0, 50]],
"adjMatrix": null,
"confused": {
"1:6": [53],
"5:3": [272, 278, 290],
"2:1": [116],
"3:5": [160],
"6:4": [330]
}
"data" : [ [ 33, 0, 0, 0, 0, 0, 0, 0 ], [ 0, 32, 0, 0, 0, 0, 1, 0 ], [ 0, 1, 33, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 31, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 33, 0, 0, 0 ], [ 0, 0, 0, 3, 0, 31, 0, 0 ], [ 0, 0, 0, 0, 1, 0, 32, 0 ], [ 0, 0, 0, 0, 0, 0, 0, 33 ] ],
"precision" : 96.99248120300751,
"adjMatrix" : null,
"confused" : {
"5:3" : [ 91, 93, 97 ],
"3:1" : [ 194 ],
"6:4" : [ 243 ],
"2:1" : [ 39 ],
"3:5" : [ 196 ],
"1:6" : [ 18 ]
}
}
\ No newline at end of file
=== Run information ===
Scheme: trees.REPTree -M 2 -V 0.001 -N 3 -S 1 -L -1 -I 0.0
Relation: BEER3
Instances: 400
Relation: BEER3-weka.filters.supervised.instance.StratifiedRemoveFolds-S0-V-N3-F1
Instances: 266
Attributes: 4
Color
Bitterness
......@@ -16,47 +16,47 @@ Test mode: 10-fold cross-validation
REPTree
============
Strength < 0.07
| Color < 6.5
| | Bitterness < 27 : 1.0 (33/0) [17/0]
| | Bitterness >= 27 : 3.0 (33/0) [15/0]
| Color >= 6.5
| | Color < 29.5
| | | Color < 16.5 : 2.0 (32/0) [19/2]
| | | Color >= 16.5 : 7.0 (34/1) [16/0]
| | Color >= 29.5 : 5.0 (34/1) [15/0]
Strength >= 0.07
| Bitterness < 47 : 8.0 (33/0) [19/3]
Color < 20
| Bitterness < 47
| | Color < 6.5
| | | Bitterness < 26 : 1.0 (22/0) [11/0]
| | | Bitterness >= 26 : 3.0 (22/0) [8/0]
| | Color >= 6.5 : 2.0 (23/1) [10/0]
| Bitterness >= 47
| | Strength < 0.09 : 4.0 (36/4) [17/2]
| | Strength >= 0.09 : 6.0 (31/1) [16/1]
| | Strength < 0.09 : 4.0 (23/2) [15/4]
| | Strength >= 0.09 : 6.0 (21/1) [10/0]
Color >= 20
| Strength < 0.08
| | Color < 29.5 : 7.0 (21/0) [12/1]
| | Color >= 29.5 : 5.0 (23/1) [11/0]
| Strength >= 0.08 : 8.0 (22/0) [12/1]
Size of the tree : 15
=== Summary ===
Correctly Classified Instances 381 95.25 %
Incorrectly Classified Instances 19 4.75 %
Kappa statistic 0.9457
K&B Relative Info Score 37459.8716 %
K&B Information Score 1123.7961 bits 2.8095 bits/instance
Class complexity | order 0 1200 bits 3 bits/instance
Class complexity | scheme 7592.0235 bits 18.9801 bits/instance
Complexity improvement (Sf) -6392.0235 bits -15.9801 bits/instance
Mean absolute error 0.0184
Root mean squared error 0.1072
Relative absolute error 8.4131 %
Root relative squared error 32.417 %
Total Number of Instances 400
Correctly Classified Instances 252 94.7368 %
Incorrectly Classified Instances 14 5.2632 %
Kappa statistic 0.9399
K&B Relative Info Score 24782.7642 %
K&B Information Score 743.4829 bits 2.795 bits/instance
Class complexity | order 0 798.8128 bits 3.0031 bits/instance
Class complexity | scheme 6484.9152 bits 24.3794 bits/instance
Complexity improvement (Sf) -5686.1025 bits -21.3763 bits/instance
Mean absolute error 0.0204
Root mean squared error 0.1095
Relative absolute error 9.3309 %
Root relative squared error 33.0997 %
Total Number of Instances 266
=== Confusion Matrix ===
a b c d e f g h <-- classified as
50 0 0 0 0 0 0 0 | a = 1.0
0 49 0 0 0 0 1 0 | b = 2.0
0 2 48 0 0 0 0 0 | c = 3.0
0 1 0 46 0 3 0 0 | d = 4.0
0 0 0 0 50 0 0 0 | e = 5.0
0 1 0 5 0 40 0 4 | f = 6.0
0 0 0 0 1 0 49 0 | g = 7.0
0 0 0 0 0 1 0 49 | h = 8.0
32 0 1 0 0 0 0 0 | a = 1.0
0 33 0 0 0 0 0 0 | b = 2.0
0 1 33 0 0 0 0 0 | c = 3.0
0 2 0 29 0 2 0 0 | d = 4.0
0 0 0 0 31 0 1 1 | e = 5.0
0 0 0 5 0 28 0 1 | f = 6.0
0 0 0 0 0 0 33 0 | g = 7.0
0 0 0 0 0 0 0 33 | h = 8.0
{
"data": [[50, 0, 0, 0, 0, 0, 0, 0], [0, 49, 0, 0, 0, 0, 1, 0], [0, 2, 48, 0, 0, 0, 0, 0], [0, 1, 0, 46, 0, 3, 0, 0], [0, 0, 0, 0, 50, 0, 0, 0], [0, 1, 0, 5, 0, 40, 0, 4], [0, 0, 0, 0, 1, 0, 49, 0], [0, 0, 0, 0, 0, 1, 0, 49]],
"adjMatrix": [[false, false, false, false, false, false, false, false], [false, false, false, false, false, false, true, false], [false, true, false, false, false, false, false, false], [false, true, false, false, false, true, false, false], [false, false, false, false, false, false, false, false], [false, true, false, true, false, false, false, true], [false, false, false, false, true, false, false, false], [false, false, false, false, false, true, false, false]],
"confused": {}
"data" : [ [ 32, 0, 1, 0, 0, 0, 0, 0 ], [ 0, 33, 0, 0, 0, 0, 0, 0 ], [ 0, 1, 33, 0, 0, 0, 0, 0 ], [ 0, 2, 0, 29, 0, 2, 0, 0 ], [ 0, 0, 0, 0, 31, 0, 1, 1 ], [ 0, 0, 0, 5, 0, 28, 0, 1 ], [ 0, 0, 0, 0, 0, 0, 33, 0 ], [ 0, 0, 0, 0, 0, 0, 0, 33 ] ],
"precision" : 94.73684210526315,
"adjMatrix" : [ [ false, false, true, false, false, false, false, false ], [ false, false, false, false, false, false, false, false ], [ false, true, false, false, false, false, false, false ], [ false, true, false, false, false, true, false, false ], [ false, false, false, false, false, false, true, true ], [ false, false, false, true, false, false, false, true ], [ false, false, false, false, false, false, false, false ], [ false, false, false, false, false, false, false, false ] ],
"confused" : { }
}
\ No newline at end of file
{
"data" : [ [ 17, 0, 0, 0, 0, 0, 0, 0 ], [ 0, 17, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 16, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 15, 0, 2, 0, 0 ], [ 0, 0, 0, 0, 17, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 16, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 17, 0 ], [ 0, 0, 0, 0, 0, 0, 0, 17 ] ],
"precision" : 98.50746268656717,
"adjMatrix" : null,
"confused" : {
"3:5" : [ 54, 65 ]
}
}
\ No newline at end of file
{
"data": [[50, 0, 0, 0, 0, 0, 0, 0], [0, 49, 0, 0, 0, 0, 1, 0], [0, 1, 49, 0, 0, 0, 0, 0], [0, 1, 0, 44, 0, 5, 0, 0], [0, 0, 0, 0, 49, 0, 0, 1], [0, 0, 0, 3, 0, 47, 0, 0], [0, 0, 0, 0, 1, 0, 49, 0], [0, 0, 0, 0, 0, 1, 0, 49]],
"adjMatrix": null,
"confused": {
"1:6": [53],
"5:3": [272, 278, 290],
"3:1": [183],
"2:1": [116],
"4:7": [234],
"3:5": [155, 159, 160, 189, 193],
"7:5": [356],
"6:4": [330]
}
"data" : [ [ 33, 0, 0, 0, 0, 0, 0, 0 ], [ 0, 32, 0, 0, 0, 0, 1, 0 ], [ 0, 1, 30, 3, 0, 0, 0, 0 ], [ 0, 0, 0, 30, 0, 3, 0, 0 ], [ 0, 0, 0, 0, 33, 0, 0, 0 ], [ 0, 0, 0, 3, 0, 30, 0, 1 ], [ 0, 0, 0, 0, 1, 0, 32, 0 ], [ 0, 0, 0, 0, 0, 0, 0, 33 ] ],
"precision" : 95.11278195488721,
"adjMatrix" : null,
"confused" : {
"5:3" : [ 91, 93, 97 ],
"6:4" : [ 243 ],
"2:1" : [ 39 ],
"2:3" : [ 34, 36, 169 ],
"3:5" : [ 52, 186, 196 ],
"5:7" : [ 217 ],
"1:6" : [ 18 ]
}
}
\ No newline at end of file
=== Run information ===
Scheme: trees.RandomTree -K 2 -M 1.0 -V 0.001 -S 1
Relation: BEER3
Instances: 400
Relation: BEER3-weka.filters.supervised.instance.StratifiedRemoveFolds-S0-V-N3-F1
Instances: 266
Attributes: 4