Package weka.gui.visualize

Examples of weka.gui.visualize.PlotData2D


   * @param name  the name of the plot
   * @return    the plot or null if plot instances weren't saved for visualization
   * @throws Exception  if plot generation fails
   */
  protected PlotData2D createPlotData(String name) throws Exception {
    PlotData2D   result;
    if (!m_SaveForVisualization)
      return null;
   
    result = new PlotData2D(m_PlotInstances);
    result.setShapeSize(m_PlotSizes);
    result.setShapeType(m_PlotShapes);
    result.setPlotName(name + " (" + m_Instances.relationName() + ")");
//    result.addInstanceNumberAttribute();

    return result;
  }
View Full Code Here


          textTitle);
      notifyTextListeners(te);

                  // set up visualizable errors
                  if (m_visualizableErrorListeners.size() > 0) {
                    PlotData2D errorD = m_PlotInstances.getPlotData(
                  textTitle + " " + textOptions);
                    VisualizableErrorEvent vel =
                      new VisualizableErrorEvent(ClassifierPerformanceEvaluator.this, errorD);
                    notifyVisualizableErrorListeners(vel);
                    m_PlotInstances.cleanUp();
                  }
                 

      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 = "<html><font size=-2>"
          + 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 + "<br>"
          + " (class: "
                      +ce.getTestSet().getDataSet().
                        classAttribute().value(0) + ")"
                      + "</font></html>";
        pd.setPlotName(textTitle + " (class: "
                        +ce.getTestSet().getDataSet().
                          classAttribute().value(0) + ")");
        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

        +"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);
    String relationName = m_visualizeDataSet.relationName();
    pd1.setPlotName(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);
   
    String relationName = m_visualizeDataSet.relationName();
   
    // A bit of a nasty hack. Allows producers of instances-based
    // events to specify that the points should be connected
    if (relationName.startsWith("__")) {
      boolean[] connect = new boolean[m_visualizeDataSet.numInstances()];
      for (int i = 1; i < connect.length; i++) { connect[i] = true; }
      pd1.setConnectPoints(connect);
      relationName = relationName.substring(2);
    }
    pd1.setPlotName(relationName);
    try {
      vis.setMasterPlot(pd1);
    } catch (Exception ex) {
      System.err.println("Problem setting up "
             +"visualization (DataVisualizer)");
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("CostBenefitTest");
      jf.setSize(1000,600);
      //jf.pack();
      jf.getContentPane().setLayout(new BorderLayout());
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("Visualize threshold curve");
    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);
    //VisualizePanel vmc = new VisualizePanel();
    ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
    vmc.setROCString("(Area under ROC = " +
         Utils.doubleToString(ThresholdCurve.getROCArea(result), 4) + ")");
    vmc.setLog(m_Log);
    vmc.setName(result.relationName()+". (Class value "+
          classAtt.value(classValue)+")");
    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("Cost/Benefit analysis");
    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 += " (class = " + classAttToUse.value(0) + ")";               
               
                // 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("Visualize cost curve");
    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 {
    CostCurve cc = new CostCurve();
    Instances result = cc.getCurve(preds, classValue);
    VisualizePanel vmc = new VisualizePanel();
    vmc.setLog(m_Log);
    vmc.setName(result.relationName()+". (Class value "+
          classAtt.value(classValue)+")");
    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

     * 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

              textTitle);
        notifyTextListeners(te);

        // set up visualizable errors
        if (m_visualizableErrorListeners.size() > 0) {
          PlotData2D errorD = new PlotData2D(m_aggregatedPlotInstances);
          errorD.setShapeSize(m_aggregatedPlotSizes);
          errorD.setShapeType(m_aggregatedPlotShapes);
          errorD.setPlotName(textTitle + " " + textOptions);
         
/*          PlotData2D errorD = m_PlotInstances.getPlotData(
              textTitle + " " + textOptions); */
          VisualizableErrorEvent vel =
            new VisualizableErrorEvent(ClassifierPerformanceEvaluator.this, errorD);
          notifyVisualizableErrorListeners(vel);
          m_PlotInstances.cleanUp();
        }


        if (testData.classAttribute().isNominal() &&
            m_thresholdListeners.size() > 0) {
          ThresholdCurve tc = new ThresholdCurve();
          Instances result = tc.getCurve(m_eval.predictions(), 0);
          result.
          setRelationName(testData.relationName());
          PlotData2D pd = new PlotData2D(result);
          String htmlTitle = "<html><font size=-2>"
            + 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 + "<br>"
          + " (class: "
          + testData.classAttribute().value(0) + ")"
          + "</font></html>";
          pd.setPlotName(textTitle + " (class: "
              + testData.classAttribute().value(0) + ")");
          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, testData.classAttribute());
          notifyThresholdListeners(rde);
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.