⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkattributeselection.java

📁 这是关于数据挖掘的一些算法
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
   * instances, instance weights.   *   * @param nominalPredictor if true use nominal predictor attributes   * @param numericPredictor if true use numeric predictor attributes   * @param stringPredictor if true use string predictor attributes   * @param datePredictor if true use date predictor attributes   * @param relationalPredictor if true use relational predictor attributes   * @param multiInstance whether multi-instance is needed   * @param classType the class type (NUMERIC, NOMINAL, etc.)   * @param predictorMissing true if we know the scheme can handle   * (at least) moderate missing predictor values   * @param classMissing true if we know the scheme can handle   * (at least) moderate missing class values   * @return index 0 is true if the test was passed   */  protected boolean[] datasetIntegrity(      boolean nominalPredictor,      boolean numericPredictor,       boolean stringPredictor,       boolean datePredictor,      boolean relationalPredictor,      boolean multiInstance,      int classType,      boolean predictorMissing,      boolean classMissing) {        print("scheme doesn't alter original datasets");    printAttributeSummary(        nominalPredictor, numericPredictor, stringPredictor, datePredictor, relationalPredictor, multiInstance, classType);    print("...");    int numTrain = getNumInstances(),     numClasses = 2, missingLevel = 20;        boolean[] result = new boolean[2];    Instances train = null;    Instances trainCopy = null;    ASSearch search = null;    ASEvaluation evaluation = null;    try {      train = makeTestDataset(42, numTrain,                               nominalPredictor    ? getNumNominal()    : 0,                              numericPredictor    ? getNumNumeric()    : 0,                               stringPredictor     ? getNumString()     : 0,                               datePredictor       ? getNumDate()       : 0,                               relationalPredictor ? getNumRelational() : 0,                               numClasses,                               classType,                              multiInstance);      if (missingLevel > 0)        addMissing(train, missingLevel, predictorMissing, classMissing);      search = ASSearch.makeCopies(getSearch(), 1)[0];      evaluation = ASEvaluation.makeCopies(getEvaluator(), 1)[0];      trainCopy = new Instances(train);    } catch (Exception ex) {      throw new Error("Error setting up for tests: " + ex.getMessage());    }    try {      search(search, evaluation, trainCopy);      compareDatasets(train, trainCopy);            println("yes");      result[0] = true;    } catch (Exception ex) {      println("no");      result[0] = false;            if (m_Debug) {        println("\n=== Full Report ===");        print("Problem during training");        println(": " + ex.getMessage() + "\n");        println("Here are the datasets:\n");        println("=== Train Dataset (original) ===\n"            + trainCopy.toString() + "\n");        println("=== Train Dataset ===\n"            + train.toString() + "\n");      }    }        return result;  }    /**   * Runs a text on the datasets with the given characteristics.   *    * @param nominalPredictor if true use nominal predictor attributes   * @param numericPredictor if true use numeric predictor attributes   * @param stringPredictor if true use string predictor attributes   * @param datePredictor if true use date predictor attributes   * @param relationalPredictor if true use relational predictor attributes   * @param multiInstance whether multi-instance is needed   * @param classType the class type (NUMERIC, NOMINAL, etc.)   * @param missingLevel the percentage of missing values   * @param predictorMissing true if the missing values may be in    * the predictors   * @param classMissing true if the missing values may be in the class   * @param numTrain the number of instances in the training set   * @param numClasses the number of classes   * @param accepts the acceptable string in an exception   * @return index 0 is true if the test was passed, index 1 is true if test    *         was acceptable   */  protected boolean[] runBasicTest(boolean nominalPredictor,      boolean numericPredictor,       boolean stringPredictor,      boolean datePredictor,      boolean relationalPredictor,      boolean multiInstance,      int classType,      int missingLevel,      boolean predictorMissing,      boolean classMissing,      int numTrain,      int numClasses,      FastVector accepts) {        return runBasicTest(		nominalPredictor, 		numericPredictor,		stringPredictor,		datePredictor,		relationalPredictor,		multiInstance,		classType, 		TestInstances.CLASS_IS_LAST,		missingLevel,		predictorMissing,		classMissing,		numTrain,		numClasses,		accepts);  }    /**   * Runs a text on the datasets with the given characteristics.   *    * @param nominalPredictor if true use nominal predictor attributes   * @param numericPredictor if true use numeric predictor attributes   * @param stringPredictor if true use string predictor attributes   * @param datePredictor if true use date predictor attributes   * @param relationalPredictor if true use relational predictor attributes   * @param multiInstance whether multi-instance is needed   * @param classType the class type (NUMERIC, NOMINAL, etc.)   * @param classIndex the attribute index of the class   * @param missingLevel the percentage of missing values   * @param predictorMissing true if the missing values may be in    * the predictors   * @param classMissing true if the missing values may be in the class   * @param numTrain the number of instances in the training set   * @param numClasses the number of classes   * @param accepts the acceptable string in an exception   * @return index 0 is true if the test was passed, index 1 is true if test    *         was acceptable   */  protected boolean[] runBasicTest(boolean nominalPredictor,      boolean numericPredictor,       boolean stringPredictor,      boolean datePredictor,      boolean relationalPredictor,      boolean multiInstance,      int classType,      int classIndex,      int missingLevel,      boolean predictorMissing,      boolean classMissing,      int numTrain,      int numClasses,      FastVector accepts) {        boolean[] result = new boolean[2];    Instances train = null;    ASSearch search = null;    ASEvaluation evaluation = null;    try {      train = makeTestDataset(42, numTrain,                               nominalPredictor    ? getNumNominal()    : 0,                              numericPredictor    ? getNumNumeric()    : 0,                               stringPredictor     ? getNumString()     : 0,                              datePredictor       ? getNumDate()       : 0,                              relationalPredictor ? getNumRelational() : 0,                              numClasses,                               classType,                              classIndex,                              multiInstance);      if (missingLevel > 0)        addMissing(train, missingLevel, predictorMissing, classMissing);      search = ASSearch.makeCopies(getSearch(), 1)[0];      evaluation = ASEvaluation.makeCopies(getEvaluator(), 1)[0];    } catch (Exception ex) {      ex.printStackTrace();      throw new Error("Error setting up for tests: " + ex.getMessage());    }    try {      search(search, evaluation, train);      println("yes");      result[0] = true;    }     catch (Exception ex) {      boolean acceptable = false;      String msg;      if (ex.getMessage() == null)	msg = "";      else        msg = ex.getMessage().toLowerCase();      if (msg.indexOf("not in classpath") > -1)	m_ClasspathProblems = true;      for (int i = 0; i < accepts.size(); i++) {	if (msg.indexOf((String)accepts.elementAt(i)) >= 0) {	  acceptable = true;	}      }            println("no" + (acceptable ? " (OK error message)" : ""));      result[1] = acceptable;            if (m_Debug) {        println("\n=== Full Report ===");        print("Problem during training");        println(": " + ex.getMessage() + "\n");        if (!acceptable) {          if (accepts.size() > 0) {            print("Error message doesn't mention ");            for (int i = 0; i < accepts.size(); i++) {              if (i != 0) {                print(" or ");              }              print('"' + (String)accepts.elementAt(i) + '"');            }          }          println("here is the dataset:\n");          println("=== Train Dataset ===\n"              + train.toString() + "\n");        }      }    }        return result;  }    /**   * Make a simple set of instances, which can later be modified   * for use in specific tests.   *   * @param seed the random number seed   * @param numInstances the number of instances to generate   * @param numNominal the number of nominal attributes   * @param numNumeric the number of numeric attributes   * @param numString the number of string attributes   * @param numDate the number of date attributes   * @param numRelational the number of relational attributes   * @param numClasses the number of classes (if nominal class)   * @param classType the class type (NUMERIC, NOMINAL, etc.)   * @param multiInstance whether the dataset should a multi-instance dataset   * @return the test dataset   * @throws Exception if the dataset couldn't be generated   * @see #process(Instances)   */  protected Instances makeTestDataset(int seed, int numInstances,                                       int numNominal, int numNumeric,                                       int numString, int numDate,                                      int numRelational,                                      int numClasses, int classType,                                      boolean multiInstance)    throws Exception {        return makeTestDataset(		seed, 		numInstances,		numNominal,		numNumeric,		numString,		numDate, 		numRelational,		numClasses, 		classType,		TestInstances.CLASS_IS_LAST,		multiInstance);  }    /**   * Make a simple set of instances with variable position of the class    * attribute, which can later be modified for use in specific tests.   *   * @param seed the random number seed   * @param numInstances the number of instances to generate   * @param numNominal the number of nominal attributes   * @param numNumeric the number of numeric attributes   * @param numString the number of string attributes   * @param numDate the number of date attributes   * @param numRelational the number of relational attributes   * @param numClasses the number of classes (if nominal class)   * @param classType the class type (NUMERIC, NOMINAL, etc.)   * @param classIndex the index of the class (0-based, -1 as last)   * @param multiInstance whether the dataset should a multi-instance dataset   * @return the test dataset   * @throws Exception if the dataset couldn't be generated   * @see TestInstances#CLASS_IS_LAST   * @see #process(Instances)   */  protected Instances makeTestDataset(int seed, int numInstances,                                       int numNominal, int numNumeric,                                       int numString, int numDate,                                      int numRelational,                                      int numClasses, int classType,                                      int classIndex,                                      boolean multiInstance)  throws Exception {        TestInstances dataset = new TestInstances();        dataset.setSeed(seed);    dataset.setNumInstances(numInstances);    dataset.setNumNominal(numNominal);    dataset.setNumNumeric(numNumeric);    dataset.setNumString(numString);    dataset.setNumDate(numDate);    dataset.setNumRelational(numRelational);    dataset.setNumClasses(numClasses);    dataset.setClassType(classType);    dataset.setClassIndex(classIndex);    dataset.setNumClasses(numClasses);    dataset.setMultiInstance(multiInstance);    dataset.setWords(getWords());    dataset.setWordSeparators(getWordSeparators());        return process(dataset.generate());  }    /**   * Print out a short summary string for the dataset characteristics   *   * @param nominalPredictor true if nominal predictor attributes are present   * @param numericPredictor true if numeric predictor attributes are present   * @param stringPredictor true if string predictor attributes are present   * @param datePredictor true if date predictor attributes are present   * @param relationalPredictor true if relational predictor attributes are present   * @param multiInstance whether multi-instance is needed   * @param classType the class type (NUMERIC, NOMINAL, etc.)   */  protected void printAttributeSummary(boolean nominalPredictor,                                        boolean numericPredictor,                                        boolean stringPredictor,                                        boolean datePredictor,                                        boolean relationalPredictor,                                        boolean multiInstance,                                       int classType) {        String str = "";    if (numericPredictor)      str += " numeric";        if (nominalPredictor) {      if (str.length() > 0)        str += " &";      str += " nominal";    }        if (stringPredictor) {      if (str.length() > 0)        str += " &";      str += " string";    }        if (datePredictor) {      if (str.length() > 0)        str += " &";      str += " date";    }        if (relationalPredictor) {      if (str.length() > 0)        str += " &";      str += " relational";    }        str += " predictors)";        switch (classType) {      case Attribute.NUMERIC:        str = " (numeric class," + str;        break;      case Attribute.NOMINAL:        str = " (nominal class," + str;        break;      case Attribute.STRING:        str = " (string class," + str;        break;      case Attribute.DATE:        str = " (date class," + str;        break;      case Attribute.RELATIONAL:        str = " (relational class," + str;        break;    }        print(str);  }    /**   * Test method for this class   *    * @param args the commandline parameters   */  public static void main(String [] args) {    runCheck(new CheckAttributeSelection(), args);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -