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

📄 checkattributeselection.java

📁 这是关于数据挖掘的一些算法
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
      result.add(	  getSearch().getClass().getName());        result.add("-test");    if (getTestEvaluator())      result.add("eval");    else      result.add("search");        return (String[]) result.toArray(new String[result.size()]);  }    /**   * Begin the tests, reporting results to System.out   */  public void doTests() {        if (getTestObject() == null) {      println("\n=== No scheme set ===");      return;    }    println("\n=== Check on scheme: "        + getTestObject().getClass().getName()        + " ===\n");        // Start tests    m_ClasspathProblems = false;    println("--> Checking for interfaces");    canTakeOptions();    boolean weightedInstancesHandler = weightedInstancesHandler()[0];    boolean multiInstanceHandler = multiInstanceHandler()[0];    println("--> Scheme tests");    declaresSerialVersionUID();    testsPerClassType(Attribute.NOMINAL,    weightedInstancesHandler, multiInstanceHandler);    testsPerClassType(Attribute.NUMERIC,    weightedInstancesHandler, multiInstanceHandler);    testsPerClassType(Attribute.DATE,       weightedInstancesHandler, multiInstanceHandler);    testsPerClassType(Attribute.STRING,     weightedInstancesHandler, multiInstanceHandler);    testsPerClassType(Attribute.RELATIONAL, weightedInstancesHandler, multiInstanceHandler);  }    /**   * Set the evaluator to test.    *   * @param value	the evaluator to use.   */  public void setEvaluator(ASEvaluation value) {    m_Evaluator = value;  }    /**   * Get the current evaluator   *   * @return 		the current evaluator   */  public ASEvaluation getEvaluator() {    return m_Evaluator;  }    /**   * Set the search method to test.    *   * @param value	the search method to use.   */  public void setSearch(ASSearch value) {    m_Search = value;  }    /**   * Get the current search method   *   * @return 		the current search method   */  public ASSearch getSearch() {    return m_Search;  }  /**   * Sets whether the evaluator or the search method is being tested.   *    * @param value	if true then the evaluator will be tested   */  public void setTestEvaluator(boolean value) {    m_TestEvaluator = value;  }    /**   * Gets whether the evaluator is being tested or the search method.   *    * @return		true if the evaluator is being tested   */  public boolean getTestEvaluator() {    return m_TestEvaluator;  }    /**   * returns either the evaluator or the search method.   *    * @return		the object to be tested   * @see		#m_TestEvaluator   */  protected Object getTestObject() {    if (getTestEvaluator())      return getEvaluator();    else      return getSearch();  }    /**   * returns deep copies of the given object   *    * @param obj		the object to copy   * @param num		the number of copies   * @return		the deep copies   * @throws Exception	if copying fails   */  protected Object[] makeCopies(Object obj, int num) throws Exception {    if (obj == null)      throw new Exception("No object set");    Object[] objs = new Object[num];    SerializedObject so = new SerializedObject(obj);    for(int i = 0; i < objs.length; i++) {      objs[i] = so.getObject();    }        return objs;  }    /**   * Performs a attribute selection with the given search and evaluation scheme    * on the provided data. The generated AttributeSelection object is returned.   *    * @param search	the search scheme to use   * @param eval	the evaluator to use   * @param data	the data to work on   * @return		the used attribute selection object   * @throws Exception	if the attribute selection fails   */  protected AttributeSelection search(ASSearch search, ASEvaluation eval,       Instances data) throws Exception {        AttributeSelection	result;        result = new AttributeSelection();    result.setSeed(42);    result.setSearch(search);    result.setEvaluator(eval);    result.SelectAttributes(data);        return result;  }    /**   * Run a battery of tests for a given class attribute type   *   * @param classType true if the class attribute should be numeric   * @param weighted true if the scheme says it handles weights   * @param multiInstance true if the scheme handles multi-instance data   */  protected void testsPerClassType(int classType,                                    boolean weighted,                                   boolean multiInstance) {        boolean PNom = canPredict(true,  false, false, false, false, multiInstance, classType)[0];    boolean PNum = canPredict(false, true,  false, false, false, multiInstance, classType)[0];    boolean PStr = canPredict(false, false, true,  false, false, multiInstance, classType)[0];    boolean PDat = canPredict(false, false, false, true,  false, multiInstance, classType)[0];    boolean PRel;    if (!multiInstance)      PRel = canPredict(false, false, false, false,  true, multiInstance, classType)[0];    else      PRel = false;    if (PNom || PNum || PStr || PDat || PRel) {      if (weighted)        instanceWeights(PNom, PNum, PStr, PDat, PRel, multiInstance, classType);            if (classType == Attribute.NOMINAL)        canHandleNClasses(PNom, PNum, PStr, PDat, PRel, multiInstance, 4);      if (!multiInstance) {	canHandleClassAsNthAttribute(PNom, PNum, PStr, PDat, PRel, multiInstance, classType, 0);	canHandleClassAsNthAttribute(PNom, PNum, PStr, PDat, PRel, multiInstance, classType, 1);      }            canHandleZeroTraining(PNom, PNum, PStr, PDat, PRel, multiInstance, classType);      boolean handleMissingPredictors = canHandleMissing(PNom, PNum, PStr, PDat, PRel,           multiInstance, classType,           true, false, 20)[0];      if (handleMissingPredictors)        canHandleMissing(PNom, PNum, PStr, PDat, PRel, multiInstance, classType, true, false, 100);            boolean handleMissingClass = canHandleMissing(PNom, PNum, PStr, PDat, PRel,           multiInstance, classType,           false, true, 20)[0];      if (handleMissingClass)        canHandleMissing(PNom, PNum, PStr, PDat, PRel, multiInstance, classType, false, true, 100);            correctSearchInitialisation(PNom, PNum, PStr, PDat, PRel, multiInstance, classType);      datasetIntegrity(PNom, PNum, PStr, PDat, PRel, multiInstance, classType,          handleMissingPredictors, handleMissingClass);    }  }    /**   * Checks whether the scheme can take command line options.   *   * @return index 0 is true if the scheme can take options   */  protected boolean[] canTakeOptions() {        boolean[] result = new boolean[2];        print("options...");    if (getTestObject() instanceof OptionHandler) {      println("yes");      if (m_Debug) {        println("\n=== Full report ===");        Enumeration enu = ((OptionHandler) getTestObject()).listOptions();        while (enu.hasMoreElements()) {          Option option = (Option) enu.nextElement();          print(option.synopsis() + "\n"               + option.description() + "\n");        }        println("\n");      }      result[0] = true;    }    else {      println("no");      result[0] = false;    }        return result;  }    /**   * Checks whether the scheme says it can handle instance weights.   *   * @return true if the scheme handles instance weights   */  protected boolean[] weightedInstancesHandler() {        boolean[] result = new boolean[2];        print("weighted instances scheme...");    if (getTestObject() instanceof WeightedInstancesHandler) {      println("yes");      result[0] = true;    }    else {      println("no");      result[0] = false;    }        return result;  }    /**   * Checks whether the scheme handles multi-instance data.   *    * @return true if the scheme handles multi-instance data   */  protected boolean[] multiInstanceHandler() {    boolean[] result = new boolean[2];        print("multi-instance scheme...");    if (getTestObject() instanceof MultiInstanceCapabilitiesHandler) {      println("yes");      result[0] = true;    }    else {      println("no");      result[0] = false;    }        return result;  }    /**   * tests for a serialVersionUID. Fails in case the schemes don't declare   * a UID (both must!).   *   * @return index 0 is true if the scheme declares a UID   */  protected boolean[] declaresSerialVersionUID() {    boolean[] result = new boolean[2];    boolean eval;    boolean search;        print("serialVersionUID...");        eval   = !SerializationHelper.needsUID(m_Evaluator.getClass());    search = !SerializationHelper.needsUID(m_Search.getClass());        result[0] = eval && search;        if (result[0])      println("yes");    else      println("no");        return result;  }    /**   * Checks basic prediction of the scheme, for simple non-troublesome   * datasets.   *   * @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 (NOMINAL, NUMERIC, etc.)   * @return index 0 is true if the test was passed, index 1 is true if test    *         was acceptable   */  protected boolean[] canPredict(      boolean nominalPredictor,      boolean numericPredictor,       boolean stringPredictor,       boolean datePredictor,      boolean relationalPredictor,      boolean multiInstance,      int classType) {        print("basic predict");    printAttributeSummary(        nominalPredictor, numericPredictor, stringPredictor, datePredictor, relationalPredictor, multiInstance, classType);    print("...");    FastVector accepts = new FastVector();    accepts.addElement("unary");    accepts.addElement("binary");    accepts.addElement("nominal");    accepts.addElement("numeric");    accepts.addElement("string");    accepts.addElement("date");    accepts.addElement("relational");    accepts.addElement("multi-instance");    accepts.addElement("not in classpath");    int numTrain = getNumInstances(), numClasses = 2, missingLevel = 0;    boolean predictorMissing = false, classMissing = false;        return runBasicTest(nominalPredictor, numericPredictor, stringPredictor,         datePredictor, relationalPredictor,         multiInstance,        classType,         missingLevel, predictorMissing, classMissing,        numTrain, numClasses,         accepts);  }    /**   * Checks whether nominal schemes can handle more than two classes.   * If a scheme is only designed for two-class problems it should   * throw an appropriate exception for multi-class problems.   *   * @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 numClasses the number of classes to test   * @return index 0 is true if the test was passed, index 1 is true if test    *         was acceptable   */  protected boolean[] canHandleNClasses(      boolean nominalPredictor,      boolean numericPredictor,       boolean stringPredictor,       boolean datePredictor,      boolean relationalPredictor,      boolean multiInstance,      int numClasses) {        print("more than two class problems");    printAttributeSummary(        nominalPredictor, numericPredictor, stringPredictor, datePredictor, relationalPredictor, multiInstance, Attribute.NOMINAL);    print("...");    FastVector accepts = new FastVector();    accepts.addElement("number");    accepts.addElement("class");    int numTrain = getNumInstances(), missingLevel = 0;    boolean predictorMissing = false, classMissing = false;        return runBasicTest(nominalPredictor, numericPredictor, stringPredictor,                         datePredictor, relationalPredictor,                         multiInstance,                        Attribute.NOMINAL,                        missingLevel, predictorMissing, classMissing,                        numTrain, numClasses,                         accepts);  }    /**   * Checks whether the scheme can handle class attributes as Nth attribute.   *   * @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 index of the class attribute (0-based, -1 means last attribute)

⌨️ 快捷键说明

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