static void checkDataset() { Attribute[] outputs = Attributes.getOutputAttributes(); if (outputs.length != 1) { LogManager.printErr("Only datasets with one output are supported"); System.exit(1); } if (outputs[0].getType() != Attribute.NOMINAL) { LogManager.printErr("Output attribute should be nominal"); System.exit(1); } Parameters.numClasses = outputs[0].getNumNominalValues(); Parameters.numAttributes = Attributes.getInputAttributes().length; }
/** Muestra por pantalla la regla actual */ public void mostrarRegla() { Attribute a[] = Attributes.getInputAttributes(); Attribute s[] = Attributes.getOutputAttributes(); System.out.print("Regla: "); for (int i = 0; i < this.antecedentes.size(); i++) { Atributo_valor av = antecedentes.get(i); System.out.print( "(" + a[av.getAtributo()].getName() + "," + a[av.getAtributo()].getNominalValue(av.getValor().intValue()) + ")"); if (i < this.antecedentes.size() - 1) System.out.print(" & "); } System.out.println(" -> (" + s[0].getName() + "," + this.consecuente + ")"); System.out.println("------------------------------------"); }
/** * Save data in output file * * @param file_name File name * @param data Data to be saved * @param n No of patterns * @param problem Type of problem (CLASSIFICATION | REGRESSION) * @throws IOException */ public void SaveOutputFile( String file_name, double data[][], int n, String problem, double[] a, double[] b) { String line; double outputs[] = new double[Noutputs]; try { // Result file FileOutputStream file = new FileOutputStream(file_name); BufferedWriter f = new BufferedWriter(new OutputStreamWriter(file)); // File header f.write("@relation " + Attributes.getRelationName() + "\n"); f.write(Attributes.getInputAttributesHeader()); f.write(Attributes.getOutputAttributesHeader()); f.write(Attributes.getInputHeader() + "\n"); f.write(Attributes.getOutputHeader() + "\n"); f.write("@data\n"); // For all patterns for (int i = 0; i < n; i++) { // Classification if (problem.compareToIgnoreCase("Classification") == 0) { // Obtain class int Class = 0; for (int j = 1; j < Noutputs; j++) { if (data[i][Class + Ninputs] < data[i][j + Ninputs]) { Class = j; } } /* f.write(Integer.toString(Class) + " "); f.write(Integer.toString(EnsembleGetClassOfPattern(data[i]))); f.newLine(); */ f.write(Attributes.getOutputAttributes()[0].getNominalValue(Class) + " "); f.write( Attributes.getOutputAttributes()[0].getNominalValue( EnsembleGetClassOfPattern(data[i]))); f.newLine(); f.flush(); } // Regression else { if (a != null && b != null) { for (int j = 0; j < Noutputs; j++) { f.write(Double.toString((data[i][Ninputs + j] - b[j]) / a[j]) + " "); } EnsembleOutput(data[i], outputs); for (int j = 0; j < Noutputs; j++) { f.write(Double.toString((outputs[j] - b[j]) / a[j]) + " "); } f.newLine(); } else { for (int j = 0; j < Noutputs; j++) { f.write(Double.toString(data[i][Ninputs + j]) + " "); } EnsembleOutput(data[i], outputs); for (int j = 0; j < Noutputs; j++) { f.write(Double.toString(outputs[j]) + " "); } f.newLine(); } } } f.close(); file.close(); } catch (FileNotFoundException e) { System.err.println("Training file does not exist"); System.exit(1); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } }