try { grph = ((Drawable)classifier).graph(); } catch (Exception ex) { }
  protected void startClassifier() {    if (m_RunThread == null) {      m_StartBut.setEnabled(false);      m_StopBut.setEnabled(true);      m_RunThread = new Thread() {	public void run() {	  // Copy the current state of things	  m_Log.statusMessage("Setting up...");	  CostMatrix costMatrix = null;	  Instances inst = new Instances(m_Instances);	  Instances userTest = null;	  double [] predictions = null;	  Instances predInstances = null;	  if (m_TestInstances != null) {	    userTest = new Instances(m_TestInstancesCopy);	  }	  if (m_EvalWRTCostsBut.isSelected()) {	    costMatrix = new CostMatrix((CostMatrix) m_CostMatrixEditor					.getValue());	  }	  boolean outputModel = m_OutputModelBut.isSelected();	  boolean outputConfusion = m_OutputConfusionBut.isSelected();	  boolean outputPerClass = m_OutputPerClassBut.isSelected();	  boolean outputSummary = true;          boolean outputEntropy = m_OutputEntropyBut.isSelected();	  boolean saveVis = m_StorePredictionsBut.isSelected();	  int testMode = 0;	  int numFolds = 10, percent = 66;	  int classIndex = m_ClassCombo.getSelectedIndex();	  Classifier classifier = (Classifier) m_ClassifierEditor.getValue();	  StringBuffer outBuff = new StringBuffer();	  String name = (new SimpleDateFormat("HH:mm:ss - "))	  .format(new Date());	  String cname = classifier.getClass().getName();	  if (cname.startsWith("weka.classifiers.")) {	    name += cname.substring("weka.classifiers.".length());	  } else {	    name += cname;	  }	  try {	    if (m_CVBut.isSelected()) {	      testMode = 1;	      numFolds = Integer.parseInt(m_CVText.getText());	      if (numFolds <= 1) {		throw new Exception("Number of folds must be greater than 1");	      }	    } else if (m_PercentBut.isSelected()) {	      testMode = 2;	      percent = Integer.parseInt(m_PercentText.getText());	      if ((percent <= 0) || (percent >= 100)) {		throw new Exception("Percentage must be between 0 and 100");	      }	    } else if (m_TrainBut.isSelected()) {	      testMode = 3;	    } else if (m_TestSplitBut.isSelected()) {	      testMode = 4;	      // Check the test instance compatibility	      if (userTest == null) {		throw new Exception("No user test set has been opened");	      }	      if (!inst.equalHeaders(userTest)) {		throw new Exception("Train and test set are not compatible");	      }	      userTest.setClassIndex(classIndex);	    } else {	      throw new Exception("Unknown test mode");	    }	    inst.setClassIndex(classIndex);	    // Output some header information	    m_Log.logMessage("Started " + cname);	    if (m_Log instanceof TaskLogger) {	      ((TaskLogger)m_Log).taskStarted();	    }	    outBuff.append("=== Run information ===\n\n");	    outBuff.append("Scheme:       " + cname);	    if (classifier instanceof OptionHandler) {	      String [] o = ((OptionHandler) classifier).getOptions();	      outBuff.append(" " + Utils.joinOptions(o));	    }	    outBuff.append("\n");	    outBuff.append("Relation:     " + inst.relationName() + '\n');	    outBuff.append("Instances:    " + inst.numInstances() + '\n');	    outBuff.append("Attributes:   " + inst.numAttributes() + '\n');	    if (inst.numAttributes() < 100) {	      for (int i = 0; i < inst.numAttributes(); i++) {		outBuff.append("              " + inst.attribute(i).name()			       + '\n');	      }	    } else {	      outBuff.append("              [list of attributes omitted]\n");	    }	    outBuff.append("Test mode:    ");	    switch (testMode) {	      case 3: // Test on training	      outBuff.append("evaluate on training data\n");	      break;	      case 1: // CV mode	      outBuff.append("" + numFolds + "-fold cross-validation\n");	      break;	      case 2: // Percent split	      outBuff.append("split " + percent			       + "% train, remainder test\n");	      break;	      case 4: // Test on user split	      outBuff.append("user supplied test set: "			     + userTest.numInstances() + " instances\n");	      break;	    }            if (costMatrix != null) {               outBuff.append("Evaluation cost matrix:\n")               .append(costMatrix.toString()).append("\n");            }	    outBuff.append("\n");	    m_History.addResult(name, outBuff);	    m_History.setSingle(name);	    	    // Build the model and output it.	    if (outputModel || (testMode == 3) || (testMode == 4)) {	      m_Log.statusMessage("Building model on training data...");	      classifier.buildClassifier(inst);	    }	    if (outputModel) {	      outBuff.append("=== Classifier model (full training set) ===\n\n");	      outBuff.append(classifier.toString() + "\n\n");	      m_History.updateResult(name);	    }	    	    Evaluation eval = null;	    switch (testMode) {	      case 3: // Test on training	      m_Log.statusMessage("Evaluating on training data...");	      eval = new Evaluation(inst, costMatrix);	      predInstances = new Instances(inst,inst.numInstances());	      predictions = new double [inst.numInstances()];	      for (int jj=0;jj<inst.numInstances();jj++) {		predictions[jj] = 		  eval.evaluateModelOnce(classifier, inst.instance(jj));		predInstances.add(inst.instance(jj));		if ((jj % 100) == 0) {		  m_Log.statusMessage("Evaluating on training data. Processed "				      +jj+" instances...");		}	      }	      outBuff.append("=== Evaluation on training set ===\n");	      break;	      case 1: // CV mode	      m_Log.statusMessage("Randomizing instances...");	      inst.randomize(new Random(42));	      if (inst.attribute(classIndex).isNominal()) {		m_Log.statusMessage("Stratifying instances...");		inst.stratify(numFolds);	      }	      eval = new Evaluation(inst, costMatrix);	      int p_index = 0;	      predInstances = new Instances(inst,inst.numInstances());	      predictions = new double [inst.numInstances()];	      // Make some splits and do a CV	      for (int fold = 0; fold < numFolds; fold++) {		m_Log.statusMessage("Creating splits for fold "				    + (fold + 1) + "...");		Instances train = inst.trainCV(numFolds, fold);		Instances test = inst.testCV(numFolds, fold);		m_Log.statusMessage("Building model for fold "				    + (fold + 1) + "...");		classifier.buildClassifier(train);		m_Log.statusMessage("Evaluating model for fold "				    + (fold + 1) + "...");		for (int jj=0;jj<test.numInstances();jj++) {		  predictions[p_index++] = 		    eval.evaluateModelOnce(classifier, test.instance(jj));		  predInstances.add(test.instance(jj));		}		//		eval.evaluateModel(classifier, test);	      }	      if (inst.attribute(classIndex).isNominal()) {		outBuff.append("=== Stratified cross-validation ===\n");	      } else {		outBuff.append("=== Cross-validation ===\n");	      }	      break;			      case 2: // Percent split	      m_Log.statusMessage("Randomizing instances...");	      inst.randomize(new Random(42));	      int trainSize = inst.numInstances() * percent / 100;	      int testSize = inst.numInstances() - trainSize;	      Instances train = new Instances(inst, 0, trainSize);	      Instances test = new Instances(inst, trainSize, testSize);	      m_Log.statusMessage("Building model on training split...");	      classifier.buildClassifier(train);	      eval = new Evaluation(train, costMatrix);	      m_Log.statusMessage("Evaluating on test split...");	      predictions = new double [test.numInstances()];	      predInstances = new Instances(test,test.numInstances());	      for (int jj=0;jj<test.numInstances();jj++) {		predictions[jj] = 		  eval.evaluateModelOnce(classifier, test.instance(jj));		predInstances.add(test.instance(jj));		if ((jj % 100) == 0) {		  m_Log.statusMessage("Evaluating on test split. Processed "				      +jj+" instances...");		}	      }	      //	      eval.evaluateModel(classifier, test);	      outBuff.append("=== Evaluation on test split ===\n");	      break;			      case 4: // Test on user split	      m_Log.statusMessage("Evaluating on test data...");	      eval = new Evaluation(inst, costMatrix);	      predictions = new double [userTest.numInstances()];	      predInstances = new Instances(userTest,					    userTest.numInstances());	      for (int jj=0;jj<userTest.numInstances();jj++) {		predictions[jj] = 		  eval.evaluateModelOnce(classifier, userTest.instance(jj));		predInstances.add(userTest.instance(jj));		if ((jj % 100) == 0) {		  m_Log.statusMessage("Evaluating on test data. Processed "				      +jj+" instances...");		}	      }	      //	      eval.evaluateModel(classifier, userTest);	      outBuff.append("=== Evaluation on test set ===\n");	      break;	      default:	      throw new Exception("Test mode not implemented");	    }	    	    if (outputSummary) {	      outBuff.append(eval.toSummaryString(outputEntropy) + "\n");	    }	    if (inst.attribute(classIndex).isNominal()) {	      if (outputPerClass) {		outBuff.append(eval.toClassDetailsString() + "\n");	      }	      if (outputConfusion) {		outBuff.append(eval.toMatrixString() + "\n");	      }	    }	    m_History.updateResult(name);	    m_Log.logMessage("Finished " + cname);	    m_Log.statusMessage("OK");	  } catch (Exception ex) {	    m_Log.logMessage(ex.getMessage());	    m_Log.statusMessage("See error log");	  } finally {	    if (predInstances != null) {	      m_CurrentVis = new VisualizePanel();	      m_CurrentVis.setInstances(predInstances);	      m_CurrentVis.setPredictions(predictions);	      m_CurrentVis.setName(name+" ("+inst.relationName()+")");	      m_CurrentVis.setColourIndex(predInstances.classIndex());	      try {		m_CurrentVis.setXIndex(m_visXIndex); 		m_CurrentVis.setYIndex(m_visYIndex);	      } catch (Exception ex) {		System.err.println(ex);	      }	      m_CurrentVis.addActionListener(new ActionListener() {		public void actionPerformed(ActionEvent e) {		  if (m_CurrentVis.getInstances().		      relationName().		      compareTo(m_Instances.relationName()) == 0) {			setXY_VisualizeIndexes(m_CurrentVis.getXIndex(), 					       m_CurrentVis.getYIndex());		      }		}	      });	      	      if (predInstances.		  attribute(predInstances.classIndex()).isNumeric()) {		    m_CurrentVis.setPredictionsNumeric(true);		  } else {		    m_CurrentVis.setPredictionsNumeric(false);		  }	      if (saveVis) {		if (classifier instanceof Drawable) {		  String grph = null;		  Object [] vv = new Object [2];		  try {		    grph = ((Drawable)classifier).graph();		  } catch (Exception ex) {		  }		  vv[0] = m_CurrentVis;		  vv[1] = grph;		  m_History.addObject(name, vv);		} else {		  m_History.addObject(name, m_CurrentVis);		}		m_VisualizeBut.setEnabled(true);	      } else {		m_VisualizeBut.setEnabled(false);	      }	    }	    if (isInterrupted()) {	      m_Log.logMessage("Interrupted " + cname);	      m_Log.statusMessage("See error log");	    }	    m_SaveOutBut.setEnabled(true);	    m_RunThread = null;	    m_StartBut.setEnabled(true);	    m_StopBut.setEnabled(false);            if (m_Log instanceof TaskLogger) {              ((TaskLogger)m_Log).taskFinished();            }          }	}      };      m_RunThread.setPriority(Thread.MIN_PRIORITY);      m_RunThread.start();    }  }