Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
  /**
   * It does return a new header (not necessary the same header as the input file one). It only
   * includes the valid attributes, those ones defined in @inputs and @outputs (or taken as that
   * role following the keel format specification).
   *
   * @return a String with the new header
   */
  public String getNewHeader() {
    String line = "";
    Attribute[] attrs = null;

    // Getting the relation name and the attributes
    if (storeAttributesAsNonStatic && attributes != null) {
      line = "@relation " + attributes.getRelationName() + "\n";
      attrs = attributes.getInputAttributes();
    } else {
      line = "@relation " + Attributes.getRelationName() + "\n";
      attrs = Attributes.getInputAttributes();
    }

    for (int i = 0; i < attrs.length; i++) {
      line += attrs[i].toString() + "\n";
    }

    // Gettin all the outputs attributes
    if (storeAttributesAsNonStatic && attributes != null) {
      attrs = attributes.getOutputAttributes();
      line += attrs[0].toString() + "\n";

      // Getting @inputs and @outputs
      line += attributes.getInputHeader() + "\n";
      line += attributes.getOutputHeader() + "\n";
    } else {
      attrs = Attributes.getOutputAttributes();
      line += attrs[0].toString() + "\n";

      // Getting @inputs and @outputs
      line += Attributes.getInputHeader() + "\n";
      line += Attributes.getOutputHeader() + "\n";
    }

    return line;
  } // end getNewHeader
Exemplo n.º 3
0
  /**
   * This function builds the data matrix for reference data and normalizes inputs values
   *
   * @throws keel.Algorithms.Preprocess.Basic.CheckException Can not be normalized.
   */
  protected void normalizar() throws CheckException {

    int i, j, k;
    Instance temp;
    double caja[];
    StringTokenizer tokens;
    boolean nulls[];

    /*Check if dataset corresponding with a classification problem*/

    if (Attributes.getOutputNumAttributes() < 1) {
      throw new CheckException(
          "This dataset haven?t outputs, so it not corresponding to a classification problem.");
    } else if (Attributes.getOutputNumAttributes() > 1) {
      throw new CheckException("This dataset have more of one output.");
    }

    if (Attributes.getOutputAttribute(0).getType() == Attribute.REAL) {
      throw new CheckException(
          "This dataset have an input attribute with floating values, so it not corresponding to a classification problem.");
    }

    entradas = Attributes.getInputAttributes();
    salida = Attributes.getOutputAttribute(0);
    nEntradas = Attributes.getInputNumAttributes();
    tokens = new StringTokenizer(training.getHeader(), " \n\r");
    tokens.nextToken();
    relation = tokens.nextToken();

    datosTrain = new double[training.getNumInstances()][Attributes.getInputNumAttributes()];
    clasesTrain = new int[training.getNumInstances()];
    caja = new double[1];

    nulosTrain = new boolean[training.getNumInstances()][Attributes.getInputNumAttributes()];
    nominalTrain = new int[training.getNumInstances()][Attributes.getInputNumAttributes()];
    realTrain = new double[training.getNumInstances()][Attributes.getInputNumAttributes()];

    for (i = 0; i < training.getNumInstances(); i++) {
      temp = training.getInstance(i);
      nulls = temp.getInputMissingValues();
      datosTrain[i] = training.getInstance(i).getAllInputValues();
      for (j = 0; j < nulls.length; j++)
        if (nulls[j]) {
          datosTrain[i][j] = 0.0;
          nulosTrain[i][j] = true;
        }
      caja = training.getInstance(i).getAllOutputValues();
      clasesTrain[i] = (int) caja[0];
      for (k = 0; k < datosTrain[i].length; k++) {
        if (Attributes.getInputAttribute(k).getType() == Attribute.NOMINAL) {
          nominalTrain[i][k] = (int) datosTrain[i][k];
          datosTrain[i][k] /= Attributes.getInputAttribute(k).getNominalValuesList().size() - 1;
        } else {
          realTrain[i][k] = datosTrain[i][k];
          datosTrain[i][k] -= Attributes.getInputAttribute(k).getMinAttribute();
          datosTrain[i][k] /=
              Attributes.getInputAttribute(k).getMaxAttribute()
                  - Attributes.getInputAttribute(k).getMinAttribute();
          if (Double.isNaN(datosTrain[i][k])) {
            datosTrain[i][k] = realTrain[i][k];
          }
        }
      }
    }

    datosTest = new double[test.getNumInstances()][Attributes.getInputNumAttributes()];
    clasesTest = new int[test.getNumInstances()];
    caja = new double[1];

    for (i = 0; i < test.getNumInstances(); i++) {
      temp = test.getInstance(i);
      nulls = temp.getInputMissingValues();
      datosTest[i] = test.getInstance(i).getAllInputValues();
      for (j = 0; j < nulls.length; j++)
        if (nulls[j]) {
          datosTest[i][j] = 0.0;
        }
      caja = test.getInstance(i).getAllOutputValues();
      clasesTest[i] = (int) caja[0];
    }
  } // end-method