Package weka.attributeSelection

Examples of weka.attributeSelection.AttributeSelection


   * @throws Exception
   */
  public void evaluateAttributes(String corpusName, String featureSetName,
      String splitName, Instances inst, String label, Integer run,
      Integer fold) throws Exception {
    AttributeSelection ae = this.getAttributeSelection();
    ae.SelectAttributes(inst);
    double rankedAttributes[][] = ae.rankedAttributes();
    FeatureEvaluation fe = initializeFeatureEvaluation(corpusName,
        featureSetName, splitName, label, run, fold);
    List<FeatureRank> featureRanks = new ArrayList<FeatureRank>(
        rankedAttributes.length);
    for (int i = 0; i < rankedAttributes.length; i++) {
View Full Code Here


          cls.setEvaluator((ASEvaluation) m_AttributeEvaluatorEditor.getValue());
          cls.setSearch((ASSearch) m_AttributeSearchEditor.getValue());
          cmdClassifier =   cls.getClass().getName() + " "
                          + Utils.joinOptions(cls.getOptions());
         
    AttributeSelection eval = null;

    try {
      if (m_CVBut.isSelected()) {
        testMode = 1;
        numFolds = Integer.parseInt(m_CVText.getText());
        seed = Integer.parseInt(m_SeedText.getText());
        if (numFolds <= 1) {
    throw new Exception(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Exception_Text_First"));
        }
      }
     
      if (classIndex >= 0) {
        inst.setClassIndex(classIndex);
      }

      // Output some header information
      m_Log.logMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_LogMessage_Text_First") + ename);
      m_Log.logMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_LogMessage_Text_Second") + cmd);
            m_Log.logMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_LogMessage_Text_Third") + cmdFilter);
            m_Log.logMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_LogMessage_Text_Fourth") + cmdClassifier);
      if (m_Log instanceof TaskLogger) {
        ((TaskLogger)m_Log).taskStarted();
      }
      outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_First"));
      outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Second") + ename);
      if (evaluator instanceof OptionHandler) {
        String [] o = ((OptionHandler) evaluator).getOptions();
        outBuff.append(" " + Utils.joinOptions(o));
      }
      outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Third") + sname);
      if (search instanceof OptionHandler) {
        String [] o = ((OptionHandler) search).getOptions();
        outBuff.append(" " + Utils.joinOptions(o));
      }
      outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Fourth"));
      outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Fifth") + inst.relationName() + '\n');
      outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Sixth") + inst.numInstances() + '\n');
      outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Seventh") + inst.numAttributes() + '\n');
      if (inst.numAttributes() < 100) {
        for (int i = 0; i < inst.numAttributes(); i++) {
    outBuff.append("              " + inst.attribute(i).name()
             + '\n');
        }
      } else {
        outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Eigth"));
      }
      outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Nineth"));
      switch (testMode) {
        case 0: // select using all training
        outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Tenth"));
        break;
        case 1: // CV mode
        outBuff.append("" + numFolds + Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Eleventh"));
        break;
      }
      outBuff.append("\n");
      m_History.addResult(name, outBuff);
      m_History.setSingle(name);
     
      // Do the feature selection and output the results.
      m_Log.statusMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text"));
      m_History.updateResult(name);
     
      eval = new AttributeSelection();
      eval.setEvaluator(evaluator);
      eval.setSearch(search);
      eval.setFolds(numFolds);
      eval.setSeed(seed);
      if (testMode == 1) {
        eval.setXval(true);
      }
           
      switch (testMode) {
        case 0: // select using training
        m_Log.statusMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_First"));
        eval.SelectAttributes(inst);
        break;

        case 1: // CV mode
        m_Log.statusMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_Second"));
        Random random = new Random(seed);
        inst.randomize(random);
        if (inst.attribute(classIndex).isNominal()) {
    m_Log.statusMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_Third"));
    inst.stratify(numFolds);
        }
        for (int fold = 0; fold < numFolds;fold++) {
    m_Log.statusMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_Fourth")
            + (fold + 1) + Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_Fifth"));
    Instances train = inst.trainCV(numFolds, fold, random);
    m_Log.statusMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_Sixth")
            + (fold + 1) + Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_Seventh"));
   
    eval.selectAttributesCVSplit(train);
        }
        break;
        default:
        throw new Exception(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Exception_Text_Second"));
      }

      if (testMode == 0) {
        outBuff.append(eval.toResultsString());
      } else {
        outBuff.append(eval.CVResultsString());
      }
   
      outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Thirteenth"));
      m_History.updateResult(name);
      m_Log.logMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_LogMessage_Text_Fifth") + ename+" "+sname);
      m_Log.statusMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_Eigth"));
    } catch (Exception ex) {
      m_Log.logMessage(ex.getMessage());
      m_Log.statusMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_Ninth"));
    } finally {
      if (evaluator instanceof AttributeTransformer) {
        try {
    Instances transformed =
      ((AttributeTransformer)evaluator).transformedData(inst);
    transformed.
      setRelationName(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Transformed_SetRelationName_Text") + transformed.relationName());

    FastVector vv = new FastVector();
    vv.addElement(transformed);
    m_History.addObject(name, vv);
        } catch (Exception ex) {
    System.err.println(ex);
    ex.printStackTrace();
        }
      } else if (testMode == 0) {
        try {
    Instances reducedInst = eval.reduceDimensionality(inst);
    FastVector vv = new FastVector();
    vv.addElement(reducedInst);
    m_History.addObject(name, vv);
        } catch (Exception ex) {
    ex.printStackTrace();
View Full Code Here

          cls.setEvaluator((ASEvaluation) m_AttributeEvaluatorEditor.getValue());
          cls.setSearch((ASSearch) m_AttributeSearchEditor.getValue());
          cmdClassifier =   cls.getClass().getName() + " "
                          + Utils.joinOptions(cls.getOptions());
         
    AttributeSelection eval = null;

    try {
      if (m_CVBut.isSelected()) {
        testMode = 1;
        numFolds = Integer.parseInt(m_CVText.getText());
        seed = Integer.parseInt(m_SeedText.getText());
        if (numFolds <= 1) {
    throw new Exception("Number of folds must be greater than 1");
        }
      }
      inst.setClassIndex(classIndex);

      // Output some header information
      m_Log.logMessage("Started " + ename);
      m_Log.logMessage("Command: " + cmd);
            m_Log.logMessage("Filter command: " + cmdFilter);
            m_Log.logMessage("Meta-classifier command: " + cmdClassifier);
      if (m_Log instanceof TaskLogger) {
        ((TaskLogger)m_Log).taskStarted();
      }
      outBuff.append("=== Run information ===\n\n");
      outBuff.append("Evaluator:    " + ename);
      if (evaluator instanceof OptionHandler) {
        String [] o = ((OptionHandler) evaluator).getOptions();
        outBuff.append(" " + Utils.joinOptions(o));
      }
      outBuff.append("\nSearch:       " + sname);
      if (search instanceof OptionHandler) {
        String [] o = ((OptionHandler) search).getOptions();
        outBuff.append(" " + Utils.joinOptions(o));
      }
      outBuff.append("\n");
      outBuff.append("Relation:     " + inst.relationName() + '\n');
      outBuff.append("Instances:    " + inst.numInstances() + '\n');
      outBuff.append("Attributes:   " + inst.numAttributes() + '\n');
      if (inst.numAttributes() < 100) {
        for (int i = 0; i < inst.numAttributes(); i++) {
    outBuff.append("              " + inst.attribute(i).name()
             + '\n');
        }
      } else {
        outBuff.append("              [list of attributes omitted]\n");
      }
      outBuff.append("Evaluation mode:    ");
      switch (testMode) {
        case 0: // select using all training
        outBuff.append("evaluate on all training data\n");
        break;
        case 1: // CV mode
        outBuff.append("" + numFolds + "-fold cross-validation\n");
        break;
      }
      outBuff.append("\n");
      m_History.addResult(name, outBuff);
      m_History.setSingle(name);
     
      // Do the feature selection and output the results.
      m_Log.statusMessage("Doing feature selection...");
      m_History.updateResult(name);
     
      eval = new AttributeSelection();
      eval.setEvaluator(evaluator);
      eval.setSearch(search);
      eval.setFolds(numFolds);
      eval.setSeed(seed);
      if (testMode == 1) {
        eval.setXval(true);
      }
           
      switch (testMode) {
        case 0: // select using training
        m_Log.statusMessage("Evaluating on training data...");
        eval.SelectAttributes(inst);
        break;

        case 1: // CV mode
        m_Log.statusMessage("Randomizing instances...");
        Random random = new Random(seed);
        inst.randomize(random);
        if (inst.attribute(classIndex).isNominal()) {
    m_Log.statusMessage("Stratifying instances...");
    inst.stratify(numFolds);
        }
        for (int fold = 0; fold < numFolds;fold++) {
    m_Log.statusMessage("Creating splits for fold "
            + (fold + 1) + "...");
    Instances train = inst.trainCV(numFolds, fold, random);
    m_Log.statusMessage("Selecting attributes using all but fold "
            + (fold + 1) + "...");
   
    eval.selectAttributesCVSplit(train);
        }
        break;
        default:
        throw new Exception("Test mode not implemented");
      }

      if (testMode == 0) {
        outBuff.append(eval.toResultsString());
      } else {
        outBuff.append(eval.CVResultsString());
      }
   
      outBuff.append("\n");
      m_History.updateResult(name);
      m_Log.logMessage("Finished " + ename+" "+sname);
      m_Log.statusMessage("OK");
    } catch (Exception ex) {
      m_Log.logMessage(ex.getMessage());
      m_Log.statusMessage("See error log");
    } finally {
      if (evaluator instanceof AttributeTransformer) {
        try {
    Instances transformed =
      ((AttributeTransformer)evaluator).transformedData();
    transformed.
      setRelationName("AT: "+transformed.relationName());

    FastVector vv = new FastVector();
    vv.addElement(transformed);
    m_History.addObject(name, vv);
        } catch (Exception ex) {
    System.err.println(ex);
    ex.printStackTrace();
        }
      } else if (testMode == 0) {
        try {
    Instances reducedInst = eval.reduceDimensionality(inst);
    FastVector vv = new FastVector();
    vv.addElement(reducedInst);
    m_History.addObject(name, vv);
        } catch (Exception ex) {
    ex.printStackTrace();
View Full Code Here

    } else {
      // all equal weights in the training data so just use as is
      resampledData = newData;
    }

    m_AttributeSelection = new AttributeSelection();
    m_AttributeSelection.setEvaluator(m_Evaluator);
    m_AttributeSelection.setSearch(m_Search);
    long start = System.currentTimeMillis();
    m_AttributeSelection.
      SelectAttributes((m_Evaluator instanceof WeightedInstancesHandler)
View Full Code Here

          cls.setEvaluator((ASEvaluation) m_AttributeEvaluatorEditor.getValue());
          cls.setSearch((ASSearch) m_AttributeSearchEditor.getValue());
          cmdClassifier =   cls.getClass().getName() + " "
                          + Utils.joinOptions(cls.getOptions());
         
    AttributeSelection eval = null;

    try {
      if (m_CVBut.isSelected()) {
        testMode = 1;
        numFolds = Integer.parseInt(m_CVText.getText());
        seed = Integer.parseInt(m_SeedText.getText());
        if (numFolds <= 1) {
    throw new Exception("Number of folds must be greater than 1");
        }
      }
     
      if (classIndex >= 0) {
        inst.setClassIndex(classIndex);
      }

      // Output some header information
      m_Log.logMessage("Started " + ename);
      m_Log.logMessage("Command: " + cmd);
            m_Log.logMessage("Filter command: " + cmdFilter);
            m_Log.logMessage("Meta-classifier command: " + cmdClassifier);
      if (m_Log instanceof TaskLogger) {
        ((TaskLogger)m_Log).taskStarted();
      }
      outBuff.append("=== Run information ===\n\n");
      outBuff.append("Evaluator:    " + ename);
      if (evaluator instanceof OptionHandler) {
        String [] o = ((OptionHandler) evaluator).getOptions();
        outBuff.append(" " + Utils.joinOptions(o));
      }
      outBuff.append("\nSearch:       " + sname);
      if (search instanceof OptionHandler) {
        String [] o = ((OptionHandler) search).getOptions();
        outBuff.append(" " + Utils.joinOptions(o));
      }
      outBuff.append("\n");
      outBuff.append("Relation:     " + inst.relationName() + '\n');
      outBuff.append("Instances:    " + inst.numInstances() + '\n');
      outBuff.append("Attributes:   " + inst.numAttributes() + '\n');
      if (inst.numAttributes() < 100) {
        for (int i = 0; i < inst.numAttributes(); i++) {
    outBuff.append("              " + inst.attribute(i).name()
             + '\n');
        }
      } else {
        outBuff.append("              [list of attributes omitted]\n");
      }
      outBuff.append("Evaluation mode:    ");
      switch (testMode) {
        case 0: // select using all training
        outBuff.append("evaluate on all training data\n");
        break;
        case 1: // CV mode
        outBuff.append("" + numFolds + "-fold cross-validation\n");
        break;
      }
      outBuff.append("\n");
      m_History.addResult(name, outBuff);
      m_History.setSingle(name);
     
      // Do the feature selection and output the results.
      m_Log.statusMessage("Doing feature selection...");
      m_History.updateResult(name);
     
      eval = new AttributeSelection();
      eval.setEvaluator(evaluator);
      eval.setSearch(search);
      eval.setFolds(numFolds);
      eval.setSeed(seed);
      if (testMode == 1) {
        eval.setXval(true);
      }
           
      switch (testMode) {
        case 0: // select using training
        m_Log.statusMessage("Evaluating on training data...");
        eval.SelectAttributes(inst);
        break;

        case 1: // CV mode
        m_Log.statusMessage("Randomizing instances...");
        Random random = new Random(seed);
        inst.randomize(random);
        if (inst.attribute(classIndex).isNominal()) {
    m_Log.statusMessage("Stratifying instances...");
    inst.stratify(numFolds);
        }
        for (int fold = 0; fold < numFolds;fold++) {
    m_Log.statusMessage("Creating splits for fold "
            + (fold + 1) + "...");
    Instances train = inst.trainCV(numFolds, fold, random);
    m_Log.statusMessage("Selecting attributes using all but fold "
            + (fold + 1) + "...");
   
    eval.selectAttributesCVSplit(train);
        }
        break;
        default:
        throw new Exception("Test mode not implemented");
      }

      if (testMode == 0) {
        outBuff.append(eval.toResultsString());
      } else {
        outBuff.append(eval.CVResultsString());
      }
   
      outBuff.append("\n");
      m_History.updateResult(name);
      m_Log.logMessage("Finished " + ename+" "+sname);
      m_Log.statusMessage("OK");
    } catch (Exception ex) {
      m_Log.logMessage(ex.getMessage());
      m_Log.statusMessage("See error log");
    } finally {
      if (evaluator instanceof AttributeTransformer) {
        try {
    Instances transformed =
      ((AttributeTransformer)evaluator).transformedData(inst);
    transformed.
      setRelationName("AT: "+transformed.relationName());

    FastVector vv = new FastVector();
    vv.addElement(transformed);
    m_History.addObject(name, vv);
        } catch (Exception ex) {
    System.err.println(ex);
    ex.printStackTrace();
        }
      } else if (testMode == 0) {
        try {
    Instances reducedInst = eval.reduceDimensionality(inst);
    FastVector vv = new FastVector();
    vv.addElement(reducedInst);
    m_History.addObject(name, vv);
        } catch (Exception ex) {
    ex.printStackTrace();
View Full Code Here

TOP

Related Classes of weka.attributeSelection.AttributeSelection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.