Errors.java
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 3k
Category:

Windows Develop

Development Platform:

Java

  1. /*
  2.  *    This program is free software; you can redistribute it and/or modify
  3.  *    it under the terms of the GNU General Public License as published by
  4.  *    the Free Software Foundation; either version 2 of the License, or
  5.  *    (at your option) any later version.
  6.  *
  7.  *    This program is distributed in the hope that it will be useful,
  8.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.  *    GNU General Public License for more details.
  11.  *
  12.  *    You should have received a copy of the GNU General Public License
  13.  *    along with this program; if not, write to the Free Software
  14.  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15.  */
  16. /*
  17.  *    Errors.java
  18.  *    Copyright (C) 1999 Yong Wang
  19.  *
  20.  */
  21. package weka.classifiers.m5;
  22. import java.io.*;
  23. import java.util.*;
  24. import weka.core.*;
  25. /**
  26.  * Class for containing the evaluation results of a model
  27.  * @author Yong Wang (yongwang@cs.waikato.ac.nz)
  28.  * @version $Revision: 1.4 $
  29.  */
  30. public final class Errors implements Serializable {
  31.   int numInstances;         // number of total instances 
  32.   int missingInstances;     // number of instances with missing class values 
  33.   double sumErr;            // sum of errors 
  34.   double sumAbsErr;         // sum of the absolute errors 
  35.   double sumSqrErr;         // sum of the squared errors 
  36.   double meanSqrErr;        // mean squared error 
  37.   double rootMeanSqrErr;    // sqaure root of the mean squared error 
  38.   double meanAbsErr;        // mean absolute error 
  39.   /**
  40.    * Constructs an object which could contain the evaluation results of a model
  41.    * @param first the index of the first instance
  42.    * @param last the index of the last instance
  43.    */
  44.   public Errors(int first,int last){
  45.     numInstances     = last-first+1;    
  46.     missingInstances = 0;
  47.     sumErr           = 0.0;         
  48.     sumAbsErr        = 0.0;      
  49.     sumSqrErr        = 0.0;      
  50.     meanSqrErr       = 0.0;     
  51.     rootMeanSqrErr   = 0.0; 
  52.     meanAbsErr       = 0.0;     
  53.   }
  54.   /**
  55.    * Makes a copy of the Errors object
  56.    * @return the copy
  57.    */
  58.   public final Errors  copy(){
  59.     
  60.     Errors e = new Errors(0,0);
  61.     
  62.     e.numInstances     = numInstances;
  63.     e.missingInstances = missingInstances;
  64.     e.sumErr           = sumErr;
  65.     e.sumAbsErr        = sumAbsErr;
  66.     e.sumSqrErr        = sumSqrErr;
  67.     e.meanSqrErr       = meanSqrErr;
  68.     e.rootMeanSqrErr   = rootMeanSqrErr;
  69.     e.meanAbsErr       = meanAbsErr;
  70.    
  71.     return e;
  72.   }
  73.   /**
  74.    * Converts the evaluation results of a model to a string
  75.    * @return the converted string
  76.    */
  77.   public final String  toString(){
  78.     StringBuffer text = new StringBuffer();
  79.         
  80.     if(this == null)text.append("    Errors:ttnulln");
  81.     else {
  82.       text.append("    Number of instances:t" + numInstances + " (" + missingInstances + " missing)n");
  83.       text.append("    Sum of errors:tt" + sumErr + "n");
  84.       text.append("    Sum of absolute errors:t" + sumAbsErr + "n");
  85.       text.append("    Sum of squared errors:t" + sumSqrErr + "n");
  86.       text.append("    Mean squared error:tt" + meanSqrErr + "n");
  87.       text.append("    Root mean squared error:t" + rootMeanSqrErr + "n");
  88.       text.append("    Mean absolute error:t" + meanAbsErr + "n");
  89.     }
  90.     return text.toString();
  91.   }
  92. }