示例#1
0
  /**
   * Name: createClassifier Goal: Evolves a fuzzy system according to given options and dataset
   *
   * @param train_data: the data used to compute performance of a system and provide data
   *     information
   * @param options: the options used to control the genetic algorithm
   * @return boolean: indicates if creation was successful or not
   */
  public boolean createClassifier(Object train_data, String options) {
    try {
      this.setOptions(weka.core.Utils.splitOptions(options));
    } catch (Exception e) {
      this.appendError(this.getClass().getName(), "Option not recognised: " + e.getMessage());
      System.out.println("option non reconnue:");
      System.out.println(e.getMessage());
      return false;
    }

    // construction du classificateur
    // les options sont separee pour plus de lisibilite en cas d'erreur
    Instances data = null;
    if (train_data instanceof String)
      data = DataLoader.loadData(null, null, (String) train_data, true, -1);
    else if (train_data instanceof Instances) data = (Instances) train_data;
    else {
      System.out.println("train data not supported!");
      this.appendError(this.getClass().getName(), "Training data format not supported");
      return false;
    }
    this.data = data;
    Coevolution ce =
        new Coevolution(
            data,
            mutation_rate,
            crossover_rate,
            selection_rate,
            pop_size,
            num_generations,
            is_binary,
            selection_algorithm,
            error_algorithm,
            elitism_rate,
            tournament_size,
            classification_weight,
            error_weight,
            rule_number_weight,
            var_per_rule_weight,
            rule_count);
    fs = ce.evolveSystem();
    fs.setData(data);
    best_fitnesses = ce.getBestFitnesses();
    if (getLogLevel() > 2)
      this.appendInfo(this.getClass().getName(), "Classifier was successfully created and trained");
    return true;
  } /*end createClassifier*/