code: public static int getClassIndex(Instances instances, TreeModel treeModel) {
          MiningSchema miningModel = treeModel.getMiningSchema();
  
          String className = null;
          for (MiningField miningField : miningModel.getMiningFields()) {
              if (miningField.getUsageType() == FieldUsageType.PREDICTED) {
                  className = miningField.getName().getValue();
                  break;
              }
          }
  
          return instances.attribute(className).index();
      }
docs: Retrieves the index of the class attribute. This is the attribute to be predicted.
  
  @param instances The {@link weka.core.Instances}.
  @param treeModel The {@link org.dmg.pmml.TreeModel PMML TreeModel element}.
  @return An int representing the index of the class attribute.