instances = new Instances(instances);  if (!instances.classAttribute().isNominal()) throw new Exception(" Only nominal class, please.");  instances.deleteWithMissingClass(); if(Utils.eq(instances.sumOfWeights(),0)) throw new Exception(" No instances with a class value!");  if(instances.numInstances() < m_Folds) throw new Exception(" Not enough data for REP.");
if(instances.numInstances() == 0) throw new Exception(" No instances with a class value!");
  public void buildClassifier(Instances instances) throws Exception{    instances = new Instances(instances);	    if (!instances.classAttribute().isNominal())       throw new Exception(" Only nominal class, please.");	    instances.deleteWithMissingClass();    if(Utils.eq(instances.sumOfWeights(),0))      throw new Exception(" No instances with a class value!");	    if(instances.numInstances() < m_Folds)      throw new Exception(" Not enough data for REP.");        m_Random = new Random(m_Seed);     m_Total = RuleStats.numAllConditions(instances);    if(m_Debug)      System.err.println("Number of all possible conditions = "+m_Total);	    Instances data = null;    m_Filter = new ClassOrderFilter();	    // Sth. to make the class order different each time in cross-validations    Instance inst =       instances.instance((int)(m_Random.nextDouble()*(double)instances.numInstances()));    ((ClassOrderFilter)m_Filter).setSeed((long)inst.toString().hashCode());	    ((ClassOrderFilter)m_Filter).setClassOrder(ClassOrderFilter.FREQ_ASCEND);    m_Filter.setInputFormat(instances);    data = Filter.useFilter(instances, m_Filter);	    if(data == null)      throw new Exception(" Unable to randomize the class orders.");	    m_Class = data.classAttribute();	    m_Ruleset = new FastVector();    m_RulesetStats = new FastVector();    // Sort by classes frequency    double[] orderedClasses = ((ClassOrderFilter)m_Filter).getClassCounts();    if(m_Debug){      System.err.println("Sorted classes:");      for(int x=0; x < m_Class.numValues(); x++)	System.err.println(x+": "+m_Class.value(x) + " has " +			   orderedClasses[x] + " instances.");    }    // Iterate from less prevalent class to more frequent one  oneClass:	    for(int y=0; y < data.numClasses()-1; y++){ // For each class	      	          double classIndex = (double)y;      if(m_Debug){	int ci = (int)classIndex;	System.err.println("\n\nClass "+m_Class.value(ci)+"("+ci+"): "			   + orderedClasses[y] + "instances\n"+			   "=====================================\n");      }		      if(Utils.eq(orderedClasses[y],0.0)) // No data for this class	continue oneClass;			          // The expected FP/err is the proportion of the class      double all = 0;      for(int i=y; i<orderedClasses.length; i++)	all += orderedClasses[i];      double expFPRate = orderedClasses[y] / all;	    	          // DL of default rule, no theory DL, only data DL      double defDL = RuleStats.dataDL(expFPRate, 				      0.0,				      data.sumOfWeights(),				      0.0,				      orderedClasses[y]);	          if(Double.isNaN(defDL) || Double.isInfinite(defDL))	throw new Exception("Should never happen: "+			    "defDL NaN or infinite!");      if(m_Debug)	System.err.println("The default DL = "+defDL);	          data = rulesetForOneClass(expFPRate, data, classIndex, defDL);    }    // Set the default rule    RipperRule defRule = new RipperRule();    defRule.setConsequent((double)(data.numClasses()-1));    m_Ruleset.addElement(defRule);	    RuleStats defRuleStat = new RuleStats();    defRuleStat.setData(data);    defRuleStat.setNumAllConds(m_Total);    defRuleStat.addAndUpdate(defRule);    m_RulesetStats.addElement(defRuleStat);	  }