throw new Exception("All training instances coincide with test instance!");
if (bandwidth <= 0) { throw new Exception("All training instances coincide with test instance!"); }
  public double classifyInstance(Instance instance) throws Exception {    if (m_Train.numInstances() == 0) {      throw new Exception("No training instances!");    }    updateMinMax(instance);    // Get the distances to each training instance    double [] distance = new double [m_Train.numInstances()];    for (int i = 0; i < m_Train.numInstances(); i++) {      distance[i] = distance(instance, m_Train.instance(i));    }    int [] sortKey = Utils.sort(distance);    if (m_Debug) {      System.out.println("Instance Distances");      for (int i = 0; i < distance.length; i++) {	System.out.println("" + distance[sortKey[i]]);      }    }    // Determine the bandwidth    int k = sortKey.length - 1;    if (!m_UseAllK && (m_kNN < k)) {      k = m_kNN;    }    double bandwidth = distance[sortKey[k]];    // Check for bandwidth zero    if (bandwidth <= 0) {      for (int i = k + 1; i < sortKey.length; i++) {	if (distance[sortKey[i]] > bandwidth) {	  bandwidth = distance[sortKey[i]];	  break;	}      }      throw new Exception("All training instances coincide with test instance!");    }    // Rescale the distances by the bandwidth    for (int i = 0; i < distance.length; i++) {      distance[i] = distance[i] / bandwidth;    }    // Pass the distances through a weighting kernel    for (int i = 0; i < distance.length; i++) {      switch (m_WeightKernel) {      case LINEAR:	distance[i] = Math.max(1.0001 - distance[i], 0);	break;      case INVERSE:	distance[i] = 1.0 / (1.0 + distance[i]);	break;      case GAUSS:	distance[i] = Math.exp(-distance[i] * distance[i]);	break;      }    }    if (m_Debug) {      System.out.println("Instance Weights");      for (int i = 0; i < distance.length; i++) {	System.out.println("" + distance[i]);      }    }    // Set the weights on a copy of the training data    Instances weightedTrain = new Instances(m_Train, 0);    for (int i = 0; i < distance.length; i++) {      double weight = distance[sortKey[i]];      if (weight < 1e-20) {	break;      }      Instance newInst = (Instance) m_Train.instance(sortKey[i]).copy();      newInst.setWeight(newInst.weight() * weight);      weightedTrain.add(newInst);    }    if (m_Debug) {      System.out.println("Kept " + weightedTrain.numInstances() + " out of "			 + m_Train.numInstances() + " instances");    }        // Create a weighted linear regression    lr.buildClassifier(weightedTrain);    if (m_Debug) {      System.out.println("Classifying test instance: " + instance);      System.out.println("Built regression model:\n" 			 + lr.toString());    }    // Return the linear regression's prediction    return lr.classifyInstance(instance);  }