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
......@@ -4,7 +4,8 @@
"type": "numericAtt",
"id": "Strength",
"name": "Strength",
"properties": [{
"properties": [
{
"type": "numericProp",
"name": "session",
"id": 0,
......@@ -39,11 +40,13 @@
"left": 0.09,
"right": 0.136
}
}],
}
],
"interval": {
"left": 0.035,
"right": 0.136
}
},
"value": 0.0
},
"splitValue": 0.07,
"comparisonSymbol": "<=",
......@@ -53,7 +56,8 @@
"type": "numericAtt",
"id": "Color",
"name": "Color",
"properties": [{
"properties": [
{
"type": "numericProp",
"name": "pale",
"id": 0,
......@@ -97,11 +101,13 @@
"left": 29,
"right": 45
}
}],
}
],
"interval": {
"left": 0.0,
"right": 45.0
}
"left": 0,
"right": 45
},
"value": 0.0
},
"splitValue": 17.0,
"comparisonSymbol": "<=",
......@@ -111,7 +117,8 @@
"type": "numericAtt",
"id": "Color",
"name": "Color",
"properties": [{
"properties": [
{
"type": "numericProp",
"name": "pale",
"id": 0,
......@@ -155,11 +162,13 @@
"left": 29,
"right": 45
}
}],
}
],
"interval": {
"left": 0.0,
"right": 45.0
}
"left": 0,
"right": 45
},
"value": 0.0
},
"splitValue": 6.0,
"comparisonSymbol": "<=",
......@@ -169,7 +178,8 @@
"type": "numericAtt",
"id": "Bitterness",
"name": "Bitterness",
"properties": [{
"properties": [
{
"type": "numericProp",
"name": "low",
"id": 0,
......@@ -204,13 +214,15 @@
"left": 47.5,
"right": 250
}
}],
}
],
"interval": {
"left": 7.0,
"right": 250.0
}
"left": 7,
"right": 250
},
"value": 0.0
},
"splitValue": 26.0,
"splitValue": 25.0,
"comparisonSymbol": "<=",
"leftChild": {
"type": "consequentNode",
......@@ -232,71 +244,12 @@
}
},
"rightChild": {
"type": "numericNode",
"attribute": {
"type": "numericAtt",
"id": "Strength",
"name": "Strength",
"properties": [{
"type": "numericProp",
"name": "session",
"id": 0,
"interval": {
"left": 0.035,
"right": 0.0525
}
},