Package weka.classifiers

Examples of weka.classifiers.Evaluation


  boolean prune = (nodeList.size() > 0);              

  //alpha_0 is always zero (unpruned tree)
  alphas[0] = 0;

  Evaluation eval;

  //error of unpruned tree
  if (errors != null) {
      eval = new Evaluation(test);
      eval.evaluateModel(this, test);
      errors[0] = eval.errorRate();
 
      
  int iteration = 0;
  while (prune) {

      iteration++;
     
      //get node with minimum alpha
      LMTNode nodeToPrune = (LMTNode)Collections.min(nodeList,comparator);

      nodeToPrune.m_isLeaf = true;
      //Do not set m_sons null, want to unprune
     
      //get alpha-value of node
      alphas[iteration] = nodeToPrune.m_alpha;
      
      //log error
      if (errors != null) {
    eval = new Evaluation(test);
    eval.evaluateModel(this, test);
    errors[iteration] = eval.errorRate();
      }

      //update errors/alphas
      treeErrors();
      calculateAlphas();
View Full Code Here


    /**
     *Updates the numIncorrectModel field for all nodes. This is needed for calculating the alpha-values.
     */
    public void modelErrors() throws Exception{
   
  Evaluation eval = new Evaluation(m_train);
   
  if (!m_isLeaf) {
      m_isLeaf = true;
      eval.evaluateModel(this, m_train);
      m_isLeaf = false;
      m_numIncorrectModel = eval.incorrect();
      for (int i = 0; i < m_sons.length; i++) m_sons[i].modelErrors();
  } else {
      eval.evaluateModel(this, m_train);
      m_numIncorrectModel = eval.incorrect();
  }
    }
View Full Code Here

     * @param data the set of instances
     * @return the error rate
     * @throws Exception if something goes wrong
     */
    protected double getErrorRate(Instances data) throws Exception {
  Evaluation eval = new Evaluation(data);
  eval.evaluateModel(this,data);
  return eval.errorRate();
    }
View Full Code Here

     * @param data the set of instances
     * @return the error
     * @throws Exception if something goes wrong
     */
    protected double getMeanAbsoluteError(Instances data) throws Exception {
  Evaluation eval = new Evaluation(data);
  eval.evaluateModel(this,data);
  return eval.meanAbsoluteError();
    }
View Full Code Here

    public void crossValidate() throws Exception {
        // stratify nominal target class
        if (_trainInstances.classAttribute().isNominal()) {
            _trainInstances.stratify(_folds);
        }
        _eval = new Evaluation(_trainInstances);
        for (int n = 0; n < _folds; n++) {

            if (_logger.isDebugEnabled()) {
                _logger.debug("Cross validation fold: " + (n + 1));
            }
View Full Code Here

     *             If model can not be evaluated
     */
    public void errorAnalysis(String attribute) throws Exception {
        readModel();
        _logger.info("Performing error analysis");
        Evaluation eval = new Evaluation(_testInstances);
        eval.evaluateModel(_cls, _testInstances);
        _predictionList = new HashMap<String, List<Prediction>>();
        String predicted, actual = null;
        double[] distribution = null;
        _predictionList.put(_config._truePositives, new ArrayList<Prediction>());
        _predictionList.put(_config._trueNegatives, new ArrayList<Prediction>());
View Full Code Here

     *             If model can not be evaluated.
     */
    public void evaluate() throws Exception {
        readModel();
        _logger.info("Classifying with " + _config._classifier);
        Evaluation eval = new Evaluation(_testInstances);
        eval.evaluateModel(_cls, _testInstances);
        _logger.info("\n" + eval.toSummaryString());
        try {
            _logger.info("\n" + eval.toClassDetailsString());
        } catch (Exception e) {
            _logger.info("Can not create class details" + _config._classifier);
        }
        try {
            _logger.info("\n" + _eval.toMatrixString());
View Full Code Here

      // Randomize the data
      data.randomize(random);
   
      // Perform cross-validation
        Instances predictedData = null;
        Evaluation eval = new Evaluation(data);
       
        for (int n = 0; n < folds; n++)
        {
          Instances train = data.trainCV(folds, n, random);
            Instances test = data.testCV(folds, n);
           
            // Apply log filter
          Filter logFilter = new LogFilter();
            logFilter.setInputFormat(train);
            train = Filter.useFilter(train, logFilter);       
            logFilter.setInputFormat(test);
            test = Filter.useFilter(test, logFilter);
           
            // Copy the classifier
            Classifier classifier = AbstractClassifier.makeCopy(baseClassifier);
                                  
            // Instantiate the FilteredClassifier
            FilteredClassifier filteredClassifier = new FilteredClassifier();
            filteredClassifier.setFilter(removeIDFilter);
            filteredClassifier.setClassifier(classifier);
              
            // Build the classifier
            filteredClassifier.buildClassifier(train);
            
            // Evaluate
            eval.evaluateModel(classifier, test);
           
            // Add predictions
            AddClassification filter = new AddClassification();
            filter.setClassifier(classifier);
            filter.setOutputClassification(true);
View Full Code Here

    // Randomize the data
    data.randomize(random);
 
    // Perform cross-validation
      Instances predictedData = null;
      Evaluation eval = new Evaluation(data);
     
      for (int n = 0; n < folds; n++)
      {
        Instances train = data.trainCV(folds, n, random);
          Instances test = data.testCV(folds, n);
         
          // Apply log filter
//        Filter logFilter = new LogFilter();
//          logFilter.setInputFormat(train);
//          train = Filter.useFilter(train, logFilter);       
//          logFilter.setInputFormat(test);
//          test = Filter.useFilter(test, logFilter);
         
          // Copy the classifier
          Classifier classifier = AbstractClassifier.makeCopy(baseClassifier);
                                
          // Instantiate the FilteredClassifier
          FilteredClassifier filteredClassifier = new FilteredClassifier();
          filteredClassifier.setFilter(removeIDFilter);
          filteredClassifier.setClassifier(classifier);
            
          // Build the classifier
          filteredClassifier.buildClassifier(train);
          
          // Evaluate
          eval.evaluateModel(filteredClassifier, test);
         
          // Add predictions
          AddClassification filter = new AddClassification();
          filter.setClassifier(filteredClassifier);
          filter.setOutputClassification(true);
View Full Code Here

      // Randomize the data
      data.randomize(random);
   
      // Perform cross-validation
        Instances predictedData = null;
        Evaluation eval = new Evaluation(data);
       
        for (int n = 0; n < folds; n++)
        {
          Instances train = data.trainCV(folds, n, random);
            Instances test = data.testCV(folds, n);
           
            // Apply log filter
          Filter logFilter = new LogFilter();
            logFilter.setInputFormat(train);
            train = Filter.useFilter(train, logFilter);       
            logFilter.setInputFormat(test);
            test = Filter.useFilter(test, logFilter);
           
            // Copy the classifier
            Classifier classifier = AbstractClassifier.makeCopy(baseClassifier);
                                  
            // Instantiate the FilteredClassifier
            FilteredClassifier filteredClassifier = new FilteredClassifier();
            filteredClassifier.setFilter(removeIDFilter);
            filteredClassifier.setClassifier(classifier);
              
            // Build the classifier
            filteredClassifier.buildClassifier(train);
            
            // Evaluate
            eval.evaluateModel(classifier, test);
           
            // Add predictions
            AddClassification filter = new AddClassification();
            filter.setClassifier(classifier);
            filter.setOutputClassification(true);
View Full Code Here

TOP

Related Classes of weka.classifiers.Evaluation

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.