int classVal = (int) newTrain.instance(i).classValue(); classCounts[classVal]++; m_ClassMeans[classVal] += instances.instance(i).classValue();
Instance inst = newTrain.instance(i); if (!inst.classIsMissing()) { int classVal = (int) inst.classValue(); classCounts[classVal]++; m_ClassMeans[classVal] += instances.instance(i).classValue(); }
  public void buildClassifier(Instances instances) throws Exception {    if (!instances.classAttribute().isNumeric()) {      throw new UnsupportedClassTypeException ("Class attribute has to be numeric");    }    // Discretize the training data    m_Discretizer.setIgnoreClass(true);    m_Discretizer.setInputFormat(instances);    Instances newTrain = Filter.useFilter(instances, m_Discretizer);    if (!newTrain.classAttribute().isNominal()) {      throw new UnsupportedClassTypeException ("Class attribute has to be nominal " +					       "after discretization");    }    int numClasses = newTrain.numClasses();    // Calculate the mean value for each bin of the new class attribute    m_ClassMeans = new double [numClasses];    int [] classCounts = new int [numClasses];    for (int i = 0; i < instances.numInstances(); i++) {      int classVal = (int) newTrain.instance(i).classValue();      classCounts[classVal]++;      m_ClassMeans[classVal] += instances.instance(i).classValue();    }    for (int i = 0; i < numClasses; i++) {      if (classCounts[i] > 0) {	m_ClassMeans[i] /= classCounts[i];      }    }    if (m_Debug) {      System.out.println("Bin Means");      System.out.println("==========");      for (int i = 0; i < m_ClassMeans.length; i++) {	System.out.println(m_ClassMeans[i]);      }      System.out.println();    }    // Train the sub-classifier    m_Classifier.buildClassifier(newTrain);  }