Package weka.clusterers

Examples of weka.clusterers.ClusterEvaluation


      }
      // copy full model for output
      SerializedObject so = new SerializedObject(clusterer);
      fullClusterer = (Clusterer) so.getObject();
     
      ClusterEvaluation eval = new ClusterEvaluation();
      eval.setClusterer(clusterer);
      switch (testMode) {
        case 3: case 5: // Test on training
        m_Log.statusMessage("Clustering training data...");
        eval.evaluateClusterer(trainInst);
        plotInstances.setInstances(inst);
        plotInstances.setClusterEvaluation(eval);
        outBuff.append("=== Model and evaluation on training set ===\n\n");
        break;

        case 2: // Percent split
        m_Log.statusMessage("Randomizing instances...");
        inst.randomize(new Random(1));
        trainInst.randomize(new Random(1));
        int trainSize = trainInst.numInstances() * percent / 100;
        int testSize = trainInst.numInstances() - trainSize;
        Instances train = new Instances(trainInst, 0, trainSize);
        Instances test = new Instances(trainInst, trainSize, testSize);
        Instances testVis = new Instances(inst, trainSize, testSize);
        m_Log.statusMessage("Building model on training split...");
        clusterer.buildClusterer(train);
        m_Log.statusMessage("Evaluating on test split...");
        eval.evaluateClusterer(test);
        plotInstances.setInstances(testVis);
        plotInstances.setClusterEvaluation(eval);
        outBuff.append("=== Model and evaluation on test split ===\n");
        break;
   
        case 4: // Test on user split
        m_Log.statusMessage("Evaluating on test data...");
        Instances userTestT = new Instances(userTest);
        if (!m_ignoreKeyList.isSelectionEmpty()) {
    userTestT = removeIgnoreCols(userTestT);
        }
        eval.evaluateClusterer(userTestT);
        plotInstances.setInstances(userTest);
        plotInstances.setClusterEvaluation(eval);
        outBuff.append("=== Model and evaluation on test set ===\n");
        break;

        default:
        throw new Exception("Test mode not implemented");
      }
      outBuff.append(eval.clusterResultsToString());
      outBuff.append("\n");
      m_History.updateResult(name);
      m_Log.logMessage("Finished " + cname);
      m_Log.statusMessage("OK");
    } catch (Exception ex) {
View Full Code Here


              m_Log.logMessage("Started reevaluate model");
              if (m_Log instanceof TaskLogger) {
                ((TaskLogger)m_Log).taskStarted();
              }
              ClusterEvaluation eval = new ClusterEvaluation();
              eval.setClusterer(clusterer);
   
              Instances userTestT = new Instances(userTest);
              if (ignoredAtts != null) {
                userTestT = removeIgnoreCols(userTestT, ignoredAtts);
              }

              eval.evaluateClusterer(userTestT);
     
              plotInstances.setClusterEvaluation(eval);
              plotInstances.setInstances(userTest);
              plotInstances.setUp();

              outBuff.append("\n=== Re-evaluation on test set ===\n\n");
              outBuff.append("User supplied test set\n")
              outBuff.append("Relation:     " + userTest.relationName() + '\n');
              outBuff.append("Instances:    " + userTest.numInstances() + '\n');
              outBuff.append("Attributes:   " + userTest.numAttributes() + "\n\n");
              if (trainHeader == null)
                outBuff.append("NOTE - if test set is not compatible then results are "
                               + "unpredictable\n\n");
     
              outBuff.append(eval.clusterResultsToString());
              outBuff.append("\n");
              m_History.updateResult(name);
              m_Log.logMessage("Finished re-evaluation");
              m_Log.statusMessage("OK");
            } catch (Exception ex) {
View Full Code Here

    }
    train.setClassIndex(-1);
    test.setClassIndex(-1);
     

    ClusterEvaluation eval = new ClusterEvaluation();

    Object [] result = new Object[overall_length];
    long trainTimeStart = System.currentTimeMillis();
    m_clusterer.buildClusterer(train);
    double numClusters = m_clusterer.numberOfClusters();
    eval.setClusterer(m_clusterer);
    long trainTimeElapsed = System.currentTimeMillis() - trainTimeStart;
    long testTimeStart = System.currentTimeMillis();
    eval.evaluateClusterer(test);
    long testTimeElapsed = System.currentTimeMillis() - testTimeStart;
    //    m_result = eval.toSummaryString();

    // The results stored are all per instance -- can be multiplied by the
    // number of instances to get absolute numbers
    int current = 0;
    result[current++] = new Double(train.numInstances());
    result[current++] = new Double(test.numInstances());

    result[current++] = new Double(eval.getLogLikelihood());
    result[current++] = new Double(numClusters);
   
    // Timing stats
    result[current++] = new Double(trainTimeElapsed / 1000.0);
    result[current++] = new Double(testTimeElapsed / 1000.0);
View Full Code Here

      }
      // copy full model for output
      SerializedObject so = new SerializedObject(clusterer);
      fullClusterer = (Clusterer) so.getObject();
     
      ClusterEvaluation eval = new ClusterEvaluation();
      eval.setClusterer(clusterer);
      switch (testMode) {
        case 3: case 5: // Test on training
        m_Log.statusMessage(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Log_StatusMessage_Third"));
        eval.evaluateClusterer(trainInst, "", false);
        predData = setUpVisualizableInstances(inst,eval);
        outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_TwentySecond"));
        break;

        case 2: // Percent split
        m_Log.statusMessage(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Log_StatusMessage_Fourth"));
        inst.randomize(new Random(1));
        trainInst.randomize(new Random(1));
        int trainSize = trainInst.numInstances() * percent / 100;
        int testSize = trainInst.numInstances() - trainSize;
        Instances train = new Instances(trainInst, 0, trainSize);
        Instances test = new Instances(trainInst, trainSize, testSize);
        Instances testVis = new Instances(inst, trainSize, testSize);
        m_Log.statusMessage(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Log_StatusMessage_Fifth"));
        trainTimeStart = System.currentTimeMillis();
        clusterer.buildClusterer(train);
        trainTimeElapsed = System.currentTimeMillis() - trainTimeStart;
       
        m_Log.statusMessage(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Log_StatusMessage_Sixth"));
        eval.evaluateClusterer(test, "", false);
        predData = setUpVisualizableInstances(testVis, eval);
        outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_TwentyThird"));
        outBuff.append(clusterer.toString() + '\n');
              outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_TimeTakenPercentage") +
                  Utils.doubleToString(trainTimeElapsed / 1000.0,2)
                  + " " + Messages.getInstance().getString("ClassifierPanel_StartClassifier_OutBuffer_Text_TwentyNineth"));
        break;
   
        case 4: // Test on user split
        m_Log.statusMessage(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Log_StatusMessage_Seventh"));
        Instances userTestT = new Instances(userTest);
        if (!m_ignoreKeyList.isSelectionEmpty()) {
    userTestT = removeIgnoreCols(userTestT);
        }
        eval.evaluateClusterer(userTestT, "", false);
        predData = setUpVisualizableInstances(userTest, eval);
        outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_TwentyFourth"));
        break;

        default:
        throw new Exception(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Exception_Text_Sixth"));
      }
      outBuff.append(eval.clusterResultsToString());
      outBuff.append("\n");
      m_History.updateResult(name);
      m_Log.logMessage(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Log_LogMessage_Text_Third") + cname);
      m_Log.statusMessage(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Log_StatusMessage_Eighth"));
    } catch (Exception ex) {
View Full Code Here

              m_Log.logMessage(Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_Log_LogMessage_Text_Third"));
              if (m_Log instanceof TaskLogger) {
                ((TaskLogger)m_Log).taskStarted();
              }
              ClusterEvaluation eval = new ClusterEvaluation();
              eval.setClusterer(clusterer);
   
              Instances userTestT = new Instances(userTest);
              if (ignoredAtts != null) {
                userTestT = removeIgnoreCols(userTestT, ignoredAtts);
              }

              eval.evaluateClusterer(userTestT);
     
              predData = setUpVisualizableInstances(userTest, eval);

              outBuff.append(Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_OutBuffer_Text_First"));
              outBuff.append(Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_OutBuffer_Text_Second"))
              outBuff.append(Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_OutBuffer_Text_Third") + userTest.relationName() + Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_OutBuffer_Text_Fourth"));
              outBuff.append(Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_OutBuffer_Text_Fifth") + userTest.numInstances() + Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_OutBuffer_Text_Sixth"));
              outBuff.append(Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_OutBuffer_Text_Seventh") + userTest.numAttributes() + Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_OutBuffer_Text_Eighth"));
              if (trainHeader == null)
                outBuff.append(Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_OutBuffer_Text_Nineth"));
     
              outBuff.append(eval.clusterResultsToString());
              outBuff.append(Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_OutBuffer_Text_Tenth"));
              m_History.updateResult(name);
              m_Log.logMessage(Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_Log_LogMessage_Text_Fourth"));
              m_Log.statusMessage(Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_Log_StatusMessage_Text_Third"));
            } catch (Exception ex) {
View Full Code Here

              boolean numericClass = false
//        final String oldText = m_visual.getText();
        try {
    if (ce.getSetNumber() == 1 /*||
        ce.getClusterer() != m_clusterer */) {
      m_eval = new ClusterEvaluation();
      m_clusterer = ce.getClusterer();
                  m_eval.setClusterer(m_clusterer);
    }
   
    if (ce.getSetNumber() <= ce.getMaxSetNumber()) {
View Full Code Here

   * @param data        the training instances
   * @throws Exception  if something goes wrong
   */
  public void buildClassifier(Instances data) throws Exception {
    Instances    clusterData;
    ClusterEvaluation  eval;
    int      i;
    Instance    instance;
    int[][]     counts;
    int[]     clusterTotals;
    double[]     best;
    double[]     current;
    double[]     clusterAssignments;
   
    // can classifier handle the data?
    getCapabilities().testWithFail(data);

    // remove instances with missing class
    data = new Instances(data);
    data.deleteWithMissingClass();

    // save original header (needed for clusters to classes output)
    m_OriginalHeader = new Instances(data, 0);
   
    // remove class attribute for clusterer
    clusterData = new Instances(data);
    clusterData.setClassIndex(-1);
    clusterData.deleteAttributeAt(m_OriginalHeader.classIndex());
    m_ClusteringHeader = new Instances(clusterData, 0);

    if (m_ClusteringHeader.numAttributes() == 0) {
      System.err.println("Data contains only class attribute, defaulting to ZeroR model.");
      m_ZeroR = new ZeroR();
      m_ZeroR.buildClassifier(data);
    }
    else {
      m_ZeroR = null;
     
      // build clusterer
      m_ActualClusterer = AbstractClusterer.makeCopy(m_Clusterer);
      m_ActualClusterer.buildClusterer(clusterData);

      // evaluate clusterer on training set
      eval = new ClusterEvaluation();
      eval.setClusterer(m_ActualClusterer);
      eval.evaluateClusterer(clusterData);
      clusterAssignments = eval.getClusterAssignments();

      // determine classes-to-clusters mapping
      counts        = new int [eval.getNumClusters()][m_OriginalHeader.numClasses()];
      clusterTotals = new int[eval.getNumClusters()];
      best          = new double[eval.getNumClusters()+1];
      current       = new double[eval.getNumClusters()+1];
      for (i = 0; i < data.numInstances(); i++) {
  instance = data.instance(i);
  counts[(int) clusterAssignments[i]][(int) instance.classValue()]++;
  clusterTotals[(int) clusterAssignments[i]]++;
  i++;
      }
      best[eval.getNumClusters()] = Double.MAX_VALUE;
      ClusterEvaluation.mapClasses(eval.getNumClusters(), 0, counts, clusterTotals, current, best, 0);
      m_ClustersToClasses = new double[best.length];
      System.arraycopy(best, 0, m_ClustersToClasses, 0, best.length);
    }
  }
View Full Code Here

    }
    train.setClassIndex(-1);
    test.setClassIndex(-1);
     

    ClusterEvaluation eval = new ClusterEvaluation();

    Object [] result = new Object[overall_length];
    long trainTimeStart = System.currentTimeMillis();
    m_clusterer.buildClusterer(train);
    double numClusters = m_clusterer.numberOfClusters();
    eval.setClusterer(m_clusterer);
    long trainTimeElapsed = System.currentTimeMillis() - trainTimeStart;
    long testTimeStart = System.currentTimeMillis();
    eval.evaluateClusterer(test);
    long testTimeElapsed = System.currentTimeMillis() - testTimeStart;
    //    m_result = eval.toSummaryString();

    // The results stored are all per instance -- can be multiplied by the
    // number of instances to get absolute numbers
    int current = 0;
    result[current++] = new Double(train.numInstances());
    result[current++] = new Double(test.numInstances());

    result[current++] = new Double(eval.getLogLikelihood());
    result[current++] = new Double(numClusters);
   
    // Timing stats
    result[current++] = new Double(trainTimeElapsed / 1000.0);
    result[current++] = new Double(testTimeElapsed / 1000.0);
View Full Code Here

      }
      // copy full model for output
      SerializedObject so = new SerializedObject(clusterer);
      fullClusterer = (Clusterer) so.getObject();
     
      ClusterEvaluation eval = new ClusterEvaluation();
      eval.setClusterer(clusterer);
      switch (testMode) {
        case 3: case 5: // Test on training
        m_Log.statusMessage("Clustering training data...");
        eval.evaluateClusterer(trainInst);
        predData = setUpVisualizableInstances(inst,eval);
        outBuff.append("=== Model and evaluation on training set ===\n\n");
        break;

        case 2: // Percent split
        m_Log.statusMessage("Randomizing instances...");
        inst.randomize(new Random(1));
        trainInst.randomize(new Random(1));
        int trainSize = trainInst.numInstances() * percent / 100;
        int testSize = trainInst.numInstances() - trainSize;
        Instances train = new Instances(trainInst, 0, trainSize);
        Instances test = new Instances(trainInst, trainSize, testSize);
        Instances testVis = new Instances(inst, trainSize, testSize);
        m_Log.statusMessage("Building model on training split...");
        clusterer.buildClusterer(train);
        m_Log.statusMessage("Evaluating on test split...");
        eval.evaluateClusterer(test);
        predData = setUpVisualizableInstances(testVis, eval);
        outBuff.append("=== Model and evaluation on test split ===\n");
        break;
   
        case 4: // Test on user split
        m_Log.statusMessage("Evaluating on test data...");
        Instances userTestT = new Instances(userTest);
        if (!m_ignoreKeyList.isSelectionEmpty()) {
    userTestT = removeIgnoreCols(userTestT);
        }
        eval.evaluateClusterer(userTestT);
        predData = setUpVisualizableInstances(userTest, eval);
        outBuff.append("=== Model and evaluation on test set ===\n");
        break;

        default:
        throw new Exception("Test mode not implemented");
      }
      outBuff.append(eval.clusterResultsToString());
      outBuff.append("\n");
      m_History.updateResult(name);
      m_Log.logMessage("Finished " + cname);
      m_Log.statusMessage("OK");
    } catch (Exception ex) {
View Full Code Here

              m_Log.logMessage("Started reevaluate model");
              if (m_Log instanceof TaskLogger) {
                ((TaskLogger)m_Log).taskStarted();
              }
              ClusterEvaluation eval = new ClusterEvaluation();
              eval.setClusterer(clusterer);
   
              Instances userTestT = new Instances(userTest);
              if (ignoredAtts != null) {
                userTestT = removeIgnoreCols(userTestT, ignoredAtts);
              }

              eval.evaluateClusterer(userTestT);
     
              predData = setUpVisualizableInstances(userTest, eval);

              outBuff.append("\n=== Re-evaluation on test set ===\n\n");
              outBuff.append("User supplied test set\n")
              outBuff.append("Relation:     " + userTest.relationName() + '\n');
              outBuff.append("Instances:    " + userTest.numInstances() + '\n');
              outBuff.append("Attributes:   " + userTest.numAttributes() + "\n\n");
              if (trainHeader == null)
                outBuff.append("NOTE - if test set is not compatible then results are "
                               + "unpredictable\n\n");
     
              outBuff.append(eval.clusterResultsToString());
              outBuff.append("\n");
              m_History.updateResult(name);
              m_Log.logMessage("Finished re-evaluation");
              m_Log.statusMessage("OK");
            } catch (Exception ex) {
View Full Code Here

TOP

Related Classes of weka.clusterers.ClusterEvaluation

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.