Package weka.gui.visualize

Examples of weka.gui.visualize.PlotData2D


            m_Log.statusMessage(Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_Log_StatusMessage_Text_First"));

            StringBuffer outBuff = m_History.getNamedBuffer(name);
            Instances userTest = null;

            PlotData2D predData = null;
            if (m_TestInstances != null) {
              userTest = new Instances(m_TestInstances);
            }
   
            boolean saveVis = m_StorePredictionsBut.isSelected();
            String grph = null;

            try {
              if (userTest == null) {
                throw new Exception(Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_Exception_Text_First"));
              }
              if (trainHeader != null && !trainHeader.equalHeaders(userTest)) {
                throw new Exception(Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_Exception_Text_Second"));
              }

              m_Log.statusMessage(Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_Log_StatusMessage_Text_Second"));
              m_Log.logMessage(Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_Log_LogMessage_Text_First") + name + Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_Log_LogMessage_Text_Second"));

              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) {
              ex.printStackTrace();
              m_Log.logMessage(ex.getMessage());
              JOptionPane.showMessageDialog(ClustererPanel.this,
                  Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_JOptionPaneShowMessageDialog_Text_First")
                                            + ex.getMessage(),
                                            Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_JOptionPaneShowMessageDialog_Text_Second"),
                                            JOptionPane.ERROR_MESSAGE);
              m_Log.statusMessage(Messages.getInstance().getString("ClustererPanel_ReEvaluateModel_Run_Log_StatusMessage_Text_Fourth"));

            } finally {
              if (predData != null) {
                m_CurrentVis = new VisualizePanel();
                m_CurrentVis.setName(name+" ("+userTest.relationName()+")");
                m_CurrentVis.setLog(m_Log);
                predData.setPlotName(name+" ("+userTest.relationName()+")");
 
                try {
                  m_CurrentVis.addPlot(predData);
                } catch (Exception ex) {
                  System.err.println(ex);
View Full Code Here


      postProcessPlotInfo(plotSize);
    }
    m_CurrentVis = new VisualizePanel();
    m_CurrentVis.setName(name+" ("+inst.relationName()+")");
    m_CurrentVis.setLog(m_Log);
    PlotData2D tempd = new PlotData2D(predInstances);
    tempd.setShapeSize(plotSize);
    tempd.setShapeType(plotShape);
    tempd.setPlotName(name+" ("+inst.relationName()+")");
    //tempd.addInstanceNumberAttribute();
   
    m_CurrentVis.addPlot(tempd);
    //m_CurrentVis.setColourIndex(predInstances.classIndex()+1);
    m_CurrentVis.setColourIndex(predInstances.classIndex());
View Full Code Here

        MarginCurve tc = new MarginCurve();
        Instances result = tc.getCurve(preds);
        VisualizePanel vmc = new VisualizePanel();
        vmc.setName(result.relationName());
        vmc.setLog(m_Log);
        PlotData2D tempd = new PlotData2D(result);
        tempd.setPlotName(result.relationName());
        tempd.addInstanceNumberAttribute();
        vmc.addPlot(tempd);
        visualizeClassifierErrors(vmc);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  });
    } else {
      visMargin.setEnabled(false);
    }
    resultListMenu.add(visMargin);

    JMenu visThreshold = new JMenu(Messages.getInstance().getString("ClassifierPanel_Visualize_VisThreshold_JMenu_Text"));
    if (preds != null && classAtt != null) {
      for (int i = 0; i < classAtt.numValues(); i++) {
  JMenuItem clv = new JMenuItem(classAtt.value(i));
  final int classValue = i;
  clv.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        try {
    ThresholdCurve tc = new ThresholdCurve();
    Instances result = tc.getCurve(preds, classValue);
    //VisualizePanel vmc = new VisualizePanel();
    ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
    vmc.setROCString(Messages.getInstance().getString("ClassifierPanel_Visualize_VMC_SetROCString_Text_First") +
         Utils.doubleToString(ThresholdCurve.getROCArea(result), 4) + Messages.getInstance().getString("ClassifierPanel_Visualize_VMC_SetROCString_Text_Second"));
    vmc.setLog(m_Log);
    vmc.setName(result.relationName()+Messages.getInstance().getString("ClassifierPanel_Visualize_VMC_SetName_Text_First") +
          classAtt.value(classValue) + Messages.getInstance().getString("ClassifierPanel_Visualize_VMC_SetName_Text_Second"));
    PlotData2D tempd = new PlotData2D(result);
    tempd.setPlotName(result.relationName());
    tempd.addInstanceNumberAttribute();
    // specify which points are connected
    boolean[] cp = new boolean[result.numInstances()];
    for (int n = 1; n < cp.length; n++)
      cp[n] = true;
    tempd.setConnectPoints(cp);
    // add plot
    vmc.addPlot(tempd);
    visualizeClassifierErrors(vmc);
        } catch (Exception ex) {
    ex.printStackTrace();
        }
        }
    });
    visThreshold.add(clv);
      }
    } else {
      visThreshold.setEnabled(false);
    }
    resultListMenu.add(visThreshold);
   
    JMenu visCostBenefit = new JMenu(Messages.getInstance().getString("ClassifierPanel_Visualize_VisCostBenefit_JMenu_Text"));
    if ((preds != null) && (classAtt != null) && (classAtt.isNominal())) {
      for (int i = 0; i < classAtt.numValues(); i++) {
        JMenuItem clv = new JMenuItem(classAtt.value(i));
        final int classValue = i;
        clv.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              try {
                ThresholdCurve tc = new ThresholdCurve();
                Instances result = tc.getCurve(preds, classValue);

                // Create a dummy class attribute with the chosen
                // class value as index 0 (if necessary).
                Attribute classAttToUse = classAtt;
                if (classValue != 0) {
                  FastVector newNames = new FastVector();
                  newNames.addElement(classAtt.value(classValue));
                  for (int k = 0; k < classAtt.numValues(); k++) {
                    if (k != classValue) {
                      newNames.addElement(classAtt.value(k));
                    }
                  }
                  classAttToUse = new Attribute(classAtt.name(), newNames);
                }
               
                CostBenefitAnalysis cbAnalysis = new CostBenefitAnalysis();
               
                PlotData2D tempd = new PlotData2D(result);
                tempd.setPlotName(result.relationName());
                tempd.m_alwaysDisplayPointsOfThisSize = 10;
                // specify which points are connected
                boolean[] cp = new boolean[result.numInstances()];
                for (int n = 1; n < cp.length; n++)
                  cp[n] = true;
                tempd.setConnectPoints(cp);
               
                String windowTitle = "";
                if (classifier != null) {
                  String cname = classifier.getClass().getName();
                  if (cname.startsWith("weka.classifiers.")) {
                    windowTitle = "" + cname.substring("weka.classifiers.".length()) + " ";
                  }
                }
                windowTitle += Messages.getInstance().getString("ClassifierPanel_Visualize_WindowTitle_Text_First") + classAttToUse.value(0) + Messages.getInstance().getString("ClassifierPanel_Visualize_WindowTitle_Text_Second");
               
                // add plot
                cbAnalysis.setCurveData(tempd, classAttToUse);
                visualizeCostBenefitAnalysis(cbAnalysis, windowTitle);
              } catch (Exception ex) {
                ex.printStackTrace();
              }
              }
          });
          visCostBenefit.add(clv);
      }
    } else {
      visCostBenefit.setEnabled(false);
    }
    resultListMenu.add(visCostBenefit);

    JMenu visCost = new JMenu(Messages.getInstance().getString("ClassifierPanel_VisCost_JMenu_Text"));
    if (preds != null && classAtt != null) {
      for (int i = 0; i < classAtt.numValues(); i++) {
  JMenuItem clv = new JMenuItem(classAtt.value(i));
  final int classValue = i;
  clv.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        try {
    CostCurve cc = new CostCurve();
    Instances result = cc.getCurve(preds, classValue);
    VisualizePanel vmc = new VisualizePanel();
    vmc.setLog(m_Log);
    vmc.setName(result.relationName()+Messages.getInstance().getString("ClassifierPanel_Visualize_VMC_SetName_Text_Third") +
          classAtt.value(classValue) + Messages.getInstance().getString("ClassifierPanel_Visualize_VMC_SetName_Text_Fourth"));
    PlotData2D tempd = new PlotData2D(result);
    tempd.m_displayAllPoints = true;
    tempd.setPlotName(result.relationName());
    boolean [] connectPoints =
      new boolean [result.numInstances()];
    for (int jj = 1; jj < connectPoints.length; jj+=2) {
      connectPoints[jj] = true;
    }
    tempd.setConnectPoints(connectPoints);
    //      tempd.addInstanceNumberAttribute();
    vmc.addPlot(tempd);
    visualizeClassifierErrors(vmc);
        } catch (Exception ex) {
    ex.printStackTrace();
View Full Code Here

                  }
                  m_CurrentVis = new VisualizePanel();
                  m_CurrentVis.setName(name+" ("
                                       +userTestStructure.relationName()+")");
                  m_CurrentVis.setLog(m_Log);
                  PlotData2D tempd = new PlotData2D(predInstances);
                  tempd.setShapeSize(plotSize);
                  tempd.setShapeType(plotShape);
                  tempd.setPlotName(name+" ("+userTestStructure.relationName()
                                    +")");
                  //tempd.addInstanceNumberAttribute();
   
                  m_CurrentVis.addPlot(tempd);
                  m_CurrentVis.setColourIndex(predInstances.classIndex());
View Full Code Here

      System.err.println(Messages.getInstance().getString("Main_InitGUI_Error_Text") + filename);
      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("Main_InitGUI_Pd1_SetPlotName_Text_First"));
    panel.setMasterPlot(pd1);
        } else {
    pd1.setPlotName(Messages.getInstance().getString("Main_InitGUI_Pd1_SetPlotName_Text_Second") + (j+1));
    pd1.m_useCustomColour = true;
    pd1.m_customColour = (j % 2 == 0) ? Color.red : Color.blue;
    panel.addPlot(pd1);
        }
      }
      catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(
      m_Self, Messages.getInstance().getString("Main_InitGUI_Exception_JOptionPaneShowMessageDialog_Text_First") + files[j] + Messages.getInstance().getString("Main_InitGUI_Exception_JOptionPaneShowMessageDialog_Text_Second") + e.getMessage());
        return;
      }
    }

    // create frame
    createFrame(
        m_Self, jMenuItemVisualizationPlot.getText() + " - " + filenames,
        panel, new BorderLayout(),
        BorderLayout.CENTER, 800, 600, null, true, true);
  }
      });

      // Visualization/ROC
      // based on this Wiki article:
      // http://weka.sourceforge.net/wiki/index.php/Visualizing_ROC_curve
      jMenuItemVisualizationROC = new JMenuItem();
      jMenuVisualization.add(jMenuItemVisualizationROC);
      jMenuItemVisualizationROC.setText(Messages.getInstance().getString("Main_InitGUI_JMenuItemVisualizationROC_SetText_Text"));
      jMenuItemVisualizationROC.setMnemonic('R');
      jMenuItemVisualizationROC.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    // 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 e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
    m_Self, Messages.getInstance().getString("Main_InitGUI_Exception_JOptionPaneShowMessageDialog_Text_Third") + filename + Messages.getInstance().getString("Main_InitGUI_Exception_JOptionPaneShowMessageDialog_Text_Fourth") + e.getMessage());
      return;
    }
    result.setClassIndex(result.numAttributes() - 1);
    ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
    vmc.setROCString(Messages.getInstance().getString("Main_InitGUI_Vmc_SetROCString_Text") +
        Utils.doubleToString(ThresholdCurve.getROCArea(result), 4) + ")");
    vmc.setName(result.relationName());
    PlotData2D tempd = new PlotData2D(result);
    tempd.setPlotName(result.relationName());
    tempd.addInstanceNumberAttribute();
    try {
      vmc.addPlot(tempd);
    }
    catch (Exception e) {
      e.printStackTrace();
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

    System.err.println("Loading instances from " + filename);
    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("Master plot");
        panel.setMasterPlot(pd1);
      } else {
        pd1.setPlotName("Plot "+(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, "Error loading file '" + files[j] + "':\n" + ex.getMessage());
      return;
    }
  }

  // create frame
  final JFrame frame = new JFrame("Plot - " + 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);
      }
    });

    m_ROCBut.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, "Error loading file '" + filename + "':\n" + ex.getMessage());
    return;
  }
  result.setClassIndex(result.numAttributes() - 1);
  ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
  vmc.setROCString("(Area under ROC = " +
      Utils.doubleToString(ThresholdCurve.getROCArea(result), 4) + ")");
  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

      System.err.println("Loading instances from " + filename);
      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("Master plot");
    panel.setMasterPlot(pd1);
        } else {
    pd1.setPlotName("Plot "+(j+1));
    pd1.m_useCustomColour = true;
    pd1.m_customColour = (j % 2 == 0) ? Color.red : Color.blue;
    panel.addPlot(pd1);
        }
      }
      catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(
      m_Self, "Error loading file '" + files[j] + "':\n" + e.getMessage());
        return;
      }
    }

    // create frame
    createFrame(
        m_Self, jMenuItemVisualizationPlot.getText() + " - " + filenames,
        panel, new BorderLayout(),
        BorderLayout.CENTER, 800, 600, null, true, true);
  }
      });

      // Visualization/ROC
      // based on this Wiki article:
      // http://weka.sourceforge.net/wiki/index.php/Visualizing_ROC_curve
      jMenuItemVisualizationROC = new JMenuItem();
      jMenuVisualization.add(jMenuItemVisualizationROC);
      jMenuItemVisualizationROC.setText("ROC");
      jMenuItemVisualizationROC.setMnemonic('R');
      jMenuItemVisualizationROC.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    // 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 e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
    m_Self, "Error loading file '" + filename + "':\n" + e.getMessage());
      return;
    }
    result.setClassIndex(result.numAttributes() - 1);
    ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
    vmc.setROCString("(Area under ROC = " +
        Utils.doubleToString(ThresholdCurve.getROCArea(result), 4) + ")");
    vmc.setName(result.relationName());
    PlotData2D tempd = new PlotData2D(result);
    tempd.setPlotName(result.relationName());
    tempd.addInstanceNumberAttribute();
    try {
      vmc.addPlot(tempd);
    }
    catch (Exception e) {
      e.printStackTrace();
View Full Code Here

        +"time. It is meant to be used if this "
        +"bean is being used programatically as as "
        +"stand alone component.");
    }
    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("Problem setting up "
       +"visualization (DataVisualizer)");
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("Problem setting up "
             +"visualization (DataVisualizer)");
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.