/** Returns True if the rule is perfect for the data set. */ public boolean perfectRule(Complejo regla, Dataset train) { ConjDatos datosTrain; datosTrain = new ConjDatos(); datosTrain = creaConjunto(train); boolean perfecta = false; /*Muestra m = datosTrain.getDato(3);//la primera instancia basicamente System.out.println(m.getClase());*/ Muestra m; ConjDatos cubiertas; cubiertas = new ConjDatos(); /*todas las instancias que cubra la regla las metemos en un conjunto*/ for (int i = 0; i < train.getndatos(); i++) { m = datosTrain.getDato(i); if (regla.cubre(m)) { cubiertas.addDato(m); } } /*perfecta sera true si todos los ejemplos del conjunto 'cubiertas' tienen la misma clase que predice la regla*/ for (int i = 0; i < cubiertas.size(); i++) { if (cubiertas.getDato(i).getClase() != regla.getClase()) { perfecta = false; return perfecta; } else perfecta = true; } return perfecta; }
/** Prints on the screen the set of rules */ public void print() { for (int i = 0; i < reglas.size(); i++) { Complejo c = (Complejo) reglas.get(i); System.out.print("\nRule " + (i + 1) + ": IF "); c.print(); System.out.print(" THEN " + nombreClase + " -> " + valorNombreClases[c.getClase()] + " "); c.printDistribucion(); } }
/** * Prints on a string the set of rules * * @return A strign that stores the set of rules */ public String printString() { String cad = ""; for (int i = 0; i < reglas.size(); i++) { Complejo c = (Complejo) reglas.get(i); cad += "\nRule " + (i + 1) + ": IF "; cad += c.printString(); cad += " THEN " + nombreClase + " -> " + valorNombreClases[c.getClase()] + " "; cad += c.printDistribucionString(); } return cad; }