Package weka.classifiers.evaluation

Examples of weka.classifiers.evaluation.EvaluationUtils


    Classifier dc = null;
    int tot = data.numInstances();
    int mid = tot / 2;
    Instances train = null;
    Instances test = null;
    EvaluationUtils evaluation = new EvaluationUtils();
   
    try {
      train = new Instances(data, 0, mid);
      test = new Instances(data, mid, tot - mid);
      dc = m_Classifier;
    }
    catch (Exception e) {
      e.printStackTrace();
      fail("Problem setting up to use classifier: " + e);
    }

    do {
      try {
  return evaluation.getTrainTestPredictions(dc, train, test);
      }
      catch (IllegalArgumentException e) {
  String msg = e.getMessage();
  if (msg.indexOf("Not enough instances") != -1) {
    System.err.println("\nInflating training data.");
View Full Code Here


  public void testRegression() throws Exception {

    PMMLClassifier classifier = null;
    Instances testData = null;
    EvaluationUtils evalUtils = null;
    weka.test.Regression reg = new weka.test.Regression(this.getClass());

    FastVector predictions = null;
    boolean success = false;
    for (int i = 0; i < m_modelNames.size(); i++) {
      classifier = getClassifier((String)m_modelNames.elementAt(i));
      testData = getData((String)m_dataSetNames.elementAt(i));
      evalUtils = new EvaluationUtils();

      try {
        String  className = classifier.getMiningSchema().getFieldsAsInstances().classAttribute().name();
        Attribute classAtt = testData.attribute(className);
        testData.setClass(classAtt);
        predictions = evalUtils.getTestPredictions(classifier, testData);
        success = true;
        String predsString = weka.classifiers.AbstractClassifierTest.predictionsToString(predictions);
        reg.println(predsString);
      } catch (Exception ex) {
        ex.printStackTrace();
View Full Code Here

    Instances     test;
    Instances     data;
    TestInstances  testInst;
    int     tot;
    int     mid;
    EvaluationUtils   evaluation;
    FastVector    regressionResults;
   
    reg = new Regression(this.getClass());

    // generate test data
    try {
      testInst = new TestInstances();
      testInst.setClassType(Attribute.NOMINAL);
      testInst.setNumNominal(5);
      testInst.setNumNominalValues(4);
      testInst.setNumNumeric(0);
      testInst.setNumDate(0);
      testInst.setNumString(0);
      testInst.setNumRelational(0);
      testInst.setNumInstances(100);
      data = testInst.generate();
    }
    catch (Exception e) {
      fail("Failed generating data: " + e);
      return;
    }
   
    // split data into train/test
    tot = data.numInstances();
    mid = tot / 2;
    train = null;
    test = null;
   
    try {
      train = new Instances(data, 0, mid);
      test = new Instances(data, mid, tot - mid);
      m_Classifier = new SerializedClassifier();
      m_Classifier.setModelFile(new File(MODEL_FILENAME));
    }
    catch (Exception e) {
      e.printStackTrace();
      fail("Problem setting up to use classifier: " + e);
    }

    evaluation = new EvaluationUtils();
    try {
      trainAndSerializeClassifier(train);
      regressionResults = evaluation.getTrainTestPredictions(m_Classifier, train, test);
      reg.println(predictionsToString(regressionResults));
    }
    catch (Exception e) {
      fail("Failed obtaining classifier predictions: " + e);
    }
View Full Code Here

   * @exception Exception if an error occurs reading the example instances.
   */
  protected void setUp() throws Exception {
    super.setUp();

    m_Evaluation = new EvaluationUtils();
    m_Instances = new Instances(
                    new BufferedReader(
                      new InputStreamReader(
                        ClassLoader.getSystemResourceAsStream(
                          "weka/classifiers/data/ClassifierTest.arff"))));
View Full Code Here

  if (valueIndex != null) {
    valueIndex.setUpper(inst.classAttribute().numValues() - 1);
  }
 
  ThresholdCurve tc = new ThresholdCurve();
  EvaluationUtils eu = new EvaluationUtils();
  FastVector predictions = new FastVector();
  for (int i = 0; i < runs; i++) {
    eu.setSeed(seed + i);
    predictions.appendElements(eu.getCVPredictions(classifier, inst, folds));
  }
 
  if (valueIndex != null)
    result = tc.getCurve(predictions, valueIndex.getIndex());
  else
View Full Code Here

  if (valueIndex != null) {
    valueIndex.setUpper(inst.classAttribute().numValues() - 1);
  }
 
  ThresholdCurve tc = new ThresholdCurve();
  EvaluationUtils eu = new EvaluationUtils();
  FastVector predictions = new FastVector();
  for (int i = 0; i < runs; i++) {
    eu.setSeed(seed + i);
    predictions.appendElements(eu.getCVPredictions(classifier, inst, folds));
  }
 
  if (valueIndex != null)
    result = tc.getCurve(predictions, valueIndex.getIndex());
  else
View Full Code Here

   * @throws Exception if an error occurs generating the predictions.
   */
  protected FastVector getPredictions(Instances instances, int mode, int numFolds)
    throws Exception {

    EvaluationUtils eu = new EvaluationUtils();
    eu.setSeed(m_Seed);
   
    switch (mode) {
    case EVAL_TUNED_SPLIT:
      Instances trainData = null, evalData = null;
      Instances data = new Instances(instances);
      Random random = new Random(m_Seed);
      data.randomize(random);
      data.stratify(numFolds);
     
      // Make sure that both subsets contain at least one positive instance
      for (int subsetIndex = 0; subsetIndex < numFolds; subsetIndex++) {
        trainData = data.trainCV(numFolds, subsetIndex, random);
        evalData = data.testCV(numFolds, subsetIndex);
        if (checkForInstance(trainData) && checkForInstance(evalData)) {
          break;
        }
      }
      return eu.getTrainTestPredictions(m_Classifier, trainData, evalData);
    case EVAL_TRAINING_SET:
      return eu.getTrainTestPredictions(m_Classifier, instances, instances);
    case EVAL_CROSS_VALIDATION:
      return eu.getCVPredictions(m_Classifier, instances, numFolds);
    default:
      throw new RuntimeException("Unrecognized evaluation mode");
    }
  }
View Full Code Here

  if (valueIndex != null) {
    valueIndex.setUpper(inst.classAttribute().numValues() - 1);
  }
 
  ThresholdCurve tc = new ThresholdCurve();
  EvaluationUtils eu = new EvaluationUtils();
  FastVector predictions = new FastVector();
  for (int i = 0; i < runs; i++) {
    eu.setSeed(seed + i);
    predictions.appendElements(eu.getCVPredictions(classifier, inst, folds));
  }
 
  if (valueIndex != null)
    result = tc.getCurve(predictions, valueIndex.getIndex());
  else
View Full Code Here

TOP

Related Classes of weka.classifiers.evaluation.EvaluationUtils

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.