public void buildClassifier(Instances insts) throws Exception {
    m_Filter = null;
    
    if (!isPresent())
      throw new Exception("libsvm classes not in CLASSPATH!");

    // remove instances with missing class
    insts = new Instances(insts);
    insts.deleteWithMissingClass();
    
    if (!getDoNotReplaceMissingValues()) {
      m_ReplaceMissingValues = new ReplaceMissingValues();
      m_ReplaceMissingValues.setInputFormat(insts);
      insts = Filter.useFilter(insts, m_ReplaceMissingValues);
    }
    
    // can classifier handle the data?
    // we check this here so that if the user turns off
    // replace missing values filtering, it will fail
    // if the data actually does have missing values
    getCapabilities().testWithFail(insts);
        
    if (getNormalize()) {
      m_Filter = new Normalize();
      m_Filter.setInputFormat(insts);
      insts = Filter.useFilter(insts, m_Filter);
    }
    
    Vector vy = new Vector();
    Vector vx = new Vector();
    int max_index = 0;
    
    for (int d = 0; d < insts.numInstances(); d++) {
      Instance inst = insts.instance(d);
      Object x = instanceToArray(inst);
      int m = Array.getLength(x);
      
      if (m > 0)
        max_index = Math.max(max_index, ((Integer) getField(Array.get(x, m - 1), "index")).intValue());
      vx.addElement(x);
      vy.addElement(new Double(inst.classValue()));
    }
    
    // calculate actual gamma
    if (getGamma() == 0)
      m_GammaActual = 1.0 / max_index;
    else
      m_GammaActual = m_Gamma;

    // check parameter
    String error_msg = (String) invokeMethod(
        Class.forName(CLASS_SVM).newInstance(), 
        "svm_check_parameter", 
        new Class[]{
          Class.forName(CLASS_SVMPROBLEM), 
          Class.forName(CLASS_SVMPARAMETER)},
        new Object[]{
          getProblem(vx, vy), 
          getParameters()});
    
    if (error_msg != null)
      throw new Exception("Error: " + error_msg);
    
    // train model
    m_Model = invokeMethod(
        Class.forName(CLASS_SVM).newInstance(), 
        "svm_train", 
        new Class[]{
          Class.forName(CLASS_SVMPROBLEM), 
          Class.forName(CLASS_SVMPARAMETER)},
        new Object[]{
          getProblem(vx, vy), 
          getParameters()});
    
    // save internal model?
    if (!m_ModelFile.isDirectory()) {
      invokeMethod(
	  Class.forName(CLASS_SVM).newInstance(), 
	  "svm_save_model", 
	  new Class[]{
	    String.class, 
	    Class.forName(CLASS_SVMMODEL)},
	    new Object[]{
	    m_ModelFile.getAbsolutePath(), 
	    m_Model});
    }
  }