Package weka.gui.visualize

Examples of weka.gui.visualize.PlotData2D


     * the threshold data.
     * @throws Exception if something goes wrong.
     */
    public synchronized void setDataSet(PlotData2D data, Attribute classAtt) throws Exception {     
      // make a copy of the PlotData2D object
      m_masterPlot = new PlotData2D(data.getPlotInstances());
      boolean[] connectPoints = new boolean[m_masterPlot.getPlotInstances().numInstances()];
      for (int i = 1; i < connectPoints.length; i++) {
        connectPoints[i] = true;
      }
      m_masterPlot.setConnectPoints(connectPoints);
View Full Code Here


      }
     
      costBenefitI.compactify();
     
      // now set up the plot data
      m_costBenefit = new PlotData2D(costBenefitI);
      m_costBenefit.m_alwaysDisplayPointsOfThisSize = 10;
      m_costBenefit.setPlotName("Cost/benefit curve");
      boolean[] connectPoints = new boolean[costBenefitI.numInstances()];
     
      for (int i = 0; i < connectPoints.length; i++) {
View Full Code Here

       new java.io.FileReader(args[0]));
      Instances inst = new Instances(r);
      final javax.swing.JFrame jf = new javax.swing.JFrame();
      jf.getContentPane().setLayout(new java.awt.BorderLayout());
      final ModelPerformanceChart as = new ModelPerformanceChart();
      PlotData2D pd = new PlotData2D(inst);
      pd.setPlotName(inst.relationName());
      ThresholdDataEvent roc = new ThresholdDataEvent(as, pd);
      as.acceptDataSet(roc);     

      jf.getContentPane().add(as, java.awt.BorderLayout.CENTER);
      jf.addWindowListener(new java.awt.event.WindowAdapter() {
View Full Code Here

  public void setInstances(Instances inst) throws Exception {
    if (m_design) {
      throw new Exception(Messages.getInstance().getString("DataVisualizer_SetInstances_Exception_Text"));
    }
    m_visualizeDataSet = inst;
    PlotData2D pd1 = new PlotData2D(m_visualizeDataSet);
    pd1.setPlotName(m_visualizeDataSet.relationName());
    try {
      m_visPanel.setMasterPlot(pd1);
    } catch (Exception ex) {
      System.err.println(Messages.getInstance().getString("DataVisualizer_SetInstances_Error_Text"));
      ex.printStackTrace();
View Full Code Here

      try {
  // popup visualize panel
  if (!m_framePoppedUp) {
    m_framePoppedUp = true;
    final VisualizePanel vis = new VisualizePanel();
    PlotData2D pd1 = new PlotData2D(m_visualizeDataSet);
    pd1.setPlotName(m_visualizeDataSet.relationName());
    try {
      vis.setMasterPlot(pd1);
    } catch (Exception ex) {
      System.err.println(Messages.getInstance().getString("DataVisualizer_PerformRequest_Error_Text"));
      ex.printStackTrace();
View Full Code Here

      weka.classifiers.Classifier classifier = new weka.classifiers.bayes.NaiveBayes();
      FastVector predictions = new FastVector();
      eu.setSeed(1);
      predictions.appendElements(eu.getCVPredictions(classifier, train, 10));
      Instances result = tc.getCurve(predictions, 0);
      PlotData2D pd = new PlotData2D(result);
      pd.m_alwaysDisplayPointsOfThisSize = 10;

      boolean[] connectPoints = new boolean[result.numInstances()];
      for (int i = 1; i < connectPoints.length; i++) {
        connectPoints[i] = true;
      }
      pd.setConnectPoints(connectPoints);
      final javax.swing.JFrame jf =
        new javax.swing.JFrame(Messages.getInstance().getString("CostBenefitAnalysis_PerformRequest_Main_JF_JFrame_Text"));
      jf.setSize(1000,600);
      //jf.pack();
      jf.getContentPane().setLayout(new BorderLayout());
View Full Code Here

          textTitle);
      notifyTextListeners(te);

                  // set up visualizable errors
                  if (m_visualizableErrorListeners.size() > 0) {
                    PlotData2D errorD = new PlotData2D(m_predInstances);
                    errorD.setShapeSize(m_plotSize);
                    errorD.setShapeType(m_plotShape);
                    errorD.setPlotName(textTitle + " " +textOptions + " ("
                                       +ce.getTestSet().getDataSet().relationName()
                                       +")");
                    errorD.addInstanceNumberAttribute();
                    VisualizableErrorEvent vel =
                      new VisualizableErrorEvent(ClassifierPerformanceEvaluator.this,
                                                 errorD);
                    notifyVisualizableErrorListeners(vel);
                  }
                 

      if (ce.getTestSet().getDataSet().classAttribute().isNominal() &&
          m_thresholdListeners.size() > 0) {
        ThresholdCurve tc = new ThresholdCurve();
        Instances result = tc.getCurve(m_eval.predictions(), 0);
        result.
          setRelationName(ce.getTestSet().getDataSet().relationName());
        PlotData2D pd = new PlotData2D(result);
        String htmlTitle = Messages.getInstance().getString("ClassifierPerformanceEvaluator_AcceptClassifier_HtmlTitle_Text_First")
          + textTitle;
        String newOptions = "";
        if (classifier instanceof OptionHandler) {
          String[] options =
            ((OptionHandler) classifier).getOptions();
          if (options.length > 0) {
            for (int ii = 0; ii < options.length; ii++) {
              if (options[ii].length() == 0) {
                continue;
              }
              if (options[ii].charAt(0) == '-' &&
                  !(options[ii].charAt(1) >= '0' &&
                      options[ii].charAt(1)<= '9')) {
                newOptions += "<br>";
              }
              newOptions += options[ii];
            }
          }
        }
       
       htmlTitle += " " + newOptions + 
          Messages.getInstance().getString("ClassifierPerformanceEvaluator_AcceptClassifier_HtmlTitle_Text_Second")
                      +ce.getTestSet().getDataSet().
                        classAttribute().value(0) + ")"
                      + Messages.getInstance().getString("ClassifierPerformanceEvaluator_AcceptClassifier_HtmlTitle_Text_Third");
        pd.setPlotName(textTitle + Messages.getInstance().getString("ClassifierPerformanceEvaluator_AcceptClassifier_HtmlTitle_Text_Fourth")
                        +ce.getTestSet().getDataSet().
                          classAttribute().value(0) + Messages.getInstance().getString("ClassifierPerformanceEvaluator_AcceptClassifier_HtmlTitle_Text_Fifth"));
        pd.setPlotNameHTML(htmlTitle);
        boolean [] connectPoints =
          new boolean [result.numInstances()];
        for (int jj = 1; jj < connectPoints.length; jj++) {
          connectPoints[jj] = true;
        }
        pd.setConnectPoints(connectPoints);
        ThresholdDataEvent rde =
          new ThresholdDataEvent(ClassifierPerformanceEvaluator.this,
               pd, ce.getTestSet().getDataSet().classAttribute());
        notifyThresholdListeners(rde);
        /*te = new TextEvent(ClassifierPerformanceEvaluator.this,
View Full Code Here

         
          try {
            Reader r = new java.io.BufferedReader(new FileReader(filename));
            Instances i = new Instances(r);
            i.setClassIndex(i.numAttributes()-1);
            PlotData2D pd1 = new PlotData2D(i);

            if (j == 0) {
              pd1.setPlotName(Messages.getInstance().getString("GUIChooser_MasterPlot_Text"));
              panel.setMasterPlot(pd1);
            } else {
              pd1.setPlotName(Messages.getInstance().getString("GUIChooser_Plot_Text") + (j+1));
              pd1.m_useCustomColour = true;
              pd1.m_customColour = (j % 2 == 0) ? Color.red : Color.blue;
              panel.addPlot(pd1);
            }
          }
          catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(
                m_Self, Messages.getInstance().getString("GUIChooser_Plot_LoadingFile_Error_Text_Front") + files[j] + Messages.getInstance().getString("GUIChooser_Plot_LoadingFile_Error_Text_End") + ex.getMessage());
            return;
          }
        }

        // create frame
        final JFrame frame = new JFrame(Messages.getInstance().getString("GUIChooser_Plot_PlotName_Text") + filenames);
        frame.setIconImage(m_Icon);
        frame.getContentPane().setLayout(new BorderLayout());
        frame.getContentPane().add(panel, BorderLayout.CENTER);
        frame.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            m_Plots.remove(frame);
            frame.dispose();
            checkExit();
          }
        });
        frame.pack();
        frame.setSize(800, 600);
        frame.setVisible(true);
        m_Plots.add(frame);
      }
    });
   
    // Visualization/ROC
    JMenuItem jMenuItemVisualizationROC = new JMenuItem();
    m_jMenuVisualization.add(jMenuItemVisualizationROC);
    jMenuItemVisualizationROC.setText(Messages.getInstance().getString("GUIChooser_ROC_Text"));
    // jMenuItemVisualizationROC.setMnemonic('R');
    jMenuItemVisualizationROC.
      setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, KeyEvent.CTRL_MASK));
   
    jMenuItemVisualizationROC.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        // choose file
        int retVal = m_FileChooserROC.showOpenDialog(m_Self);
        if (retVal != JFileChooser.APPROVE_OPTION)
          return;

        // create plot
        String filename  = m_FileChooserROC.getSelectedFile().getAbsolutePath();
        Instances result = null;
        try {
          result = new Instances(new BufferedReader(new FileReader(filename)));
        }
        catch (Exception ex) {
          ex.printStackTrace();
          JOptionPane.showMessageDialog(
              m_Self, Messages.getInstance().getString("GUIChooser_ROC_LoadingFile_Error_Text_Front") + filename + Messages.getInstance().getString("GUIChooser_ROC_LoadingFile_Error_Text_End") + ex.getMessage());
          return;
        }
        result.setClassIndex(result.numAttributes() - 1);
        ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
        vmc.setROCString(Messages.getInstance().getString("GUIChooser_ROC_AreaUnderROC_Text_Front") +
            Utils.doubleToString(ThresholdCurve.getROCArea(result), 4) + Messages.getInstance().getString("GUIChooser_ROC_AreaUnderROC_Text_End"));
        vmc.setName(result.relationName());
        PlotData2D tempd = new PlotData2D(result);
        tempd.setPlotName(result.relationName());
        tempd.addInstanceNumberAttribute();
        try {
          vmc.addPlot(tempd);
        }
        catch (Exception ex) {
          ex.printStackTrace();
View Full Code Here

        } else {
          pointShapes[i] = Plot2D.MISSING_SHAPE;
        }
      }
    }
    PlotData2D plotData = new PlotData2D(newInsts);
    if (pointShapes != null) {
      plotData.setShapeType(pointShapes);
    }
    plotData.addInstanceNumberAttribute();
    return plotData;
  }
View Full Code Here

    // Copy the current state of things
    m_Log.statusMessage(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Log_StatusMessage_Text_First"));
    Instances inst = new Instances(m_Instances);
    inst.setClassIndex(-1);
    Instances userTest = null;
    PlotData2D predData = null;
    if (m_TestInstances != null) {
      userTest = new Instances(m_TestInstances);
    }
   
    boolean saveVis = m_StorePredictionsBut.isSelected();
    String grph = null;
    int[] ignoredAtts = null;

    int testMode = 0;
    int percent = 66;
    Clusterer clusterer = (Clusterer) m_ClustererEditor.getValue();
    Clusterer fullClusterer = null;
    StringBuffer outBuff = new StringBuffer();
    String name = (new SimpleDateFormat("HH:mm:ss - "))
    .format(new Date());
    String cname = clusterer.getClass().getName();
    if (cname.startsWith("weka.clusterers.")) {
      name += cname.substring("weka.clusterers.".length());
    } else {
      name += cname;
    }
          String cmd = m_ClustererEditor.getValue().getClass().getName();
          if (m_ClustererEditor.getValue() instanceof OptionHandler)
            cmd += " " + Utils.joinOptions(((OptionHandler) m_ClustererEditor.getValue()).getOptions());
    try {
      m_Log.logMessage(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Log_LogMessage_Text_First") + cname);
      m_Log.logMessage(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Log_LogMessage_Text_Second") + cmd);
      if (m_Log instanceof TaskLogger) {
        ((TaskLogger)m_Log).taskStarted();
      }
      if (m_PercentBut.isSelected()) {
        testMode = 2;
        percent = Integer.parseInt(m_PercentText.getText());
        if ((percent <= 0) || (percent >= 100)) {
    throw new Exception(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Exception_Text_First"));
        }
      } 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(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Exception_Text_Second"));
        }
        if (!inst.equalHeaders(userTest)) {
    throw new Exception(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Exception_Text_Third"));
        }
      } else if (m_ClassesToClustersBut.isSelected()) {
        testMode = 5;
      } else {
        throw new Exception(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Exception_Text_Fourth"));
      }

      Instances trainInst = new Instances(inst);
      if (m_ClassesToClustersBut.isSelected()) {
        trainInst.setClassIndex(m_ClassCombo.getSelectedIndex());
        inst.setClassIndex(m_ClassCombo.getSelectedIndex());
        if (inst.classAttribute().isNumeric()) {
    throw new Exception(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Exception_Text_Fifth"));
        }
      }
      if (!m_ignoreKeyList.isSelectionEmpty()) {
        trainInst = removeIgnoreCols(trainInst);
      }

      // Output some header information
      outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_First"));
      outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_Second") + cname);
      if (clusterer instanceof OptionHandler) {
        String [] o = ((OptionHandler) clusterer).getOptions();
        outBuff.append(" " + Utils.joinOptions(o));
      }
      outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_Third"));
      outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_Fourth") + inst.relationName() + '\n');
      outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_Sixth") + inst.numInstances() + '\n');
      outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_Eighth") + inst.numAttributes() + '\n');
      if (inst.numAttributes() < 100) {
        boolean [] selected = new boolean [inst.numAttributes()];
        for (int i = 0; i < inst.numAttributes(); i++) {
    selected[i] = true;
        }
        if (!m_ignoreKeyList.isSelectionEmpty()) {
    int [] indices = m_ignoreKeyList.getSelectedIndices();
    for (int i = 0; i < indices.length; i++) {
      selected[indices[i]] = false;
    }
        }
        if (m_ClassesToClustersBut.isSelected()) {
    selected[m_ClassCombo.getSelectedIndex()] = false;
        }
        for (int i = 0; i < inst.numAttributes(); i++) {
    if (selected[i]) {
      outBuff.append("              " + inst.attribute(i).name()
         + '\n');
    }
        }
        if (!m_ignoreKeyList.isSelectionEmpty()
      || m_ClassesToClustersBut.isSelected()) {
    outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_Eleventh"));
    for (int i = 0; i < inst.numAttributes(); i++) {
      if (!selected[i]) {
        outBuff.append("              " + inst.attribute(i).name()
           + '\n');
      }
    }
        }
      } else {
        outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_Thirteenth"));
      }

      if (!m_ignoreKeyList.isSelectionEmpty()) {
        ignoredAtts = m_ignoreKeyList.getSelectedIndices();
      }

      if (m_ClassesToClustersBut.isSelected()) {
        // add class to ignored list
        if (ignoredAtts == null) {
    ignoredAtts = new int[1];
    ignoredAtts[0] = m_ClassCombo.getSelectedIndex();
        } else {
    int[] newIgnoredAtts = new int[ignoredAtts.length+1];
    System.arraycopy(ignoredAtts, 0, newIgnoredAtts, 0, ignoredAtts.length);
    newIgnoredAtts[ignoredAtts.length] = m_ClassCombo.getSelectedIndex();
    ignoredAtts = newIgnoredAtts;
        }
      }


      outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_Fourteenth"));
      switch (testMode) {
        case 3: // Test on training
        outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_Fifteenth"));
        break;
        case 2: // Percent split
        outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_Sixteenth") + percent
             + Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_Seventeenth"));
        break;
        case 4: // Test on user split
        outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_Eighteenth")
           + userTest.numInstances() + Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_Nineteenth"));
        break;
      case 5: // Classes to clusters evaluation on training
        outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_Twentyth"));
       
        break;
      }
      outBuff.append("\n");
      m_History.addResult(name, outBuff);
      m_History.setSingle(name);
     
      // Build the model and output it.
      m_Log.statusMessage(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Log_StatusMessage_Second"));

      trainTimeStart = System.currentTimeMillis();
      // remove the class attribute (if set) and build the clusterer
      clusterer.buildClusterer(removeClass(trainInst));
      trainTimeElapsed = System.currentTimeMillis() - trainTimeStart;
     
//      if (testMode == 2) {
        outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_TwentySecond"));
     
        outBuff.append(clusterer.toString() + '\n');
        outBuff.append(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_OutBuffer_Text_TimeTakenFull") +
                  Utils.doubleToString(trainTimeElapsed / 1000.0,2)
                  + " " + Messages.getInstance().getString("ClassifierPanel_StartClassifier_OutBuffer_Text_TwentyNineth"));
//      }
      m_History.updateResult(name);
      if (clusterer instanceof Drawable) {
        try {
    grph = ((Drawable)clusterer).graph();
        } catch (Exception ex) {
        }
      }
      // 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) {
      ex.printStackTrace();
      m_Log.logMessage(ex.getMessage());
      JOptionPane.showMessageDialog(ClustererPanel.this,
          Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_JOptionPaneShowMessageDialog_Text_First")
            + ex.getMessage(),
            Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_JOptionPaneShowMessageDialog_Text_Second"),
            JOptionPane.ERROR_MESSAGE);
      m_Log.statusMessage(Messages.getInstance().getString("ClustererPanel_StartClusterer_Run_Log_StatusMessage_Nineth"));
    } finally {
      if (predData != null) {
        m_CurrentVis = new VisualizePanel();
        m_CurrentVis.setName(name+" ("+inst.relationName()+")");
        m_CurrentVis.setLog(m_Log);
        predData.setPlotName(name+" ("+inst.relationName()+")");
       
        try {
    m_CurrentVis.addPlot(predData);
        } catch (Exception ex) {
    System.err.println(ex);
View Full Code Here

TOP

Related Classes of weka.gui.visualize.PlotData2D

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.