Package weka.core

Examples of weka.core.FastVector$FastVectorEnumeration


            JOptionPane.ERROR_MESSAGE);
      m_Log.statusMessage("Problem evaluating classifier");
    } finally {
      try {
              if (!saveVis && outputModel) {
      FastVector vv = new FastVector();
      vv.addElement(fullClassifier);
      Instances trainHeader = new Instances(m_Instances, 0);
      trainHeader.setClassIndex(classIndex);
      vv.addElement(trainHeader);
                  if (grph != null) {
        vv.addElement(grph);
      }
      m_History.addObject(name, vv);
              } else if (saveVis && plotInstances != null && plotInstances.getPlotInstances().numInstances() > 0) {
    m_CurrentVis = new VisualizePanel();
    m_CurrentVis.setName(name+" ("+inst.relationName()+")");
    m_CurrentVis.setLog(m_Log);
    m_CurrentVis.addPlot(plotInstances.getPlotData(cname));
    //m_CurrentVis.setColourIndex(plotInstances.getPlotInstances().classIndex()+1);
          m_CurrentVis.setColourIndex(plotInstances.getPlotInstances().classIndex());
    plotInstances.cleanUp();
     
                FastVector vv = new FastVector();
                if (outputModel) {
                  vv.addElement(fullClassifier);
                  Instances trainHeader = new Instances(m_Instances, 0);
                  trainHeader.setClassIndex(classIndex);
                  vv.addElement(trainHeader);
                  if (grph != null) {
                    vv.addElement(grph);
                  }
                }
                vv.addElement(m_CurrentVis);
               
                if ((eval != null) && (eval.predictions() != null)) {
                  vv.addElement(eval.predictions());
                  vv.addElement(inst.classAttribute());
                }
                m_History.addObject(name, vv);
        }
      } catch (Exception ex) {
        ex.printStackTrace();
View Full Code Here


    loadClassifier();
  }
      });
    resultListMenu.add(loadModel);

    FastVector o = null;
    if (selectedName != null) {
      o = (FastVector)m_History.getNamedObject(selectedName);
    }

    VisualizePanel temp_vp = null;
    String temp_grph = null;
    FastVector temp_preds = null;
    Attribute temp_classAtt = null;
    Classifier temp_classifier = null;
    Instances temp_trainHeader = null;
     
    if (o != null) {
      for (int i = 0; i < o.size(); i++) {
  Object temp = o.elementAt(i);
  if (temp instanceof Classifier) {
    temp_classifier = (Classifier)temp;
  } else if (temp instanceof Instances) { // training header
    temp_trainHeader = (Instances)temp;
  } else if (temp instanceof VisualizePanel) { // normal errors
    temp_vp = (VisualizePanel)temp;
  } else if (temp instanceof String) { // graphable output
    temp_grph = (String)temp;
  } else if (temp instanceof FastVector) { // predictions
    temp_preds = (FastVector)temp;
  } else if (temp instanceof Attribute) { // class attribute
    temp_classAtt = (Attribute)temp;
  }
      }
    }

    final VisualizePanel vp = temp_vp;
    final String grph = temp_grph;
    final FastVector preds = temp_preds;
    final Attribute classAtt = temp_classAtt;
    final Classifier classifier = temp_classifier;
    final Instances trainHeader = temp_trainHeader;
   
    JMenuItem saveModel = new JMenuItem("Save model");
    if (classifier != null) {
      saveModel.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      saveClassifier(selectedName, classifier, trainHeader);
    }
  });
    } else {
      saveModel.setEnabled(false);
    }
    resultListMenu.add(saveModel);

    JMenuItem reEvaluate =
      new JMenuItem("Re-evaluate model on current test set");
    if (classifier != null && m_TestLoader != null) {
      reEvaluate.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      reevaluateModel(selectedName, classifier, trainHeader);
    }
  });
    } else {
      reEvaluate.setEnabled(false);
    }
    resultListMenu.add(reEvaluate);
   
    resultListMenu.addSeparator();
   
    JMenuItem visErrors = new JMenuItem("Visualize classifier errors");
    if (vp != null) {
      if ((vp.getXIndex() == 0) && (vp.getYIndex() == 1)) {
  try {
    vp.setXIndex(vp.getInstances().classIndex())// class
    vp.setYIndex(vp.getInstances().classIndex() - 1)// predicted class
  }
  catch (Exception e) {
    // ignored
  }
      }
      visErrors.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      visualizeClassifierErrors(vp);
    }
  });
    } else {
      visErrors.setEnabled(false);
    }
    resultListMenu.add(visErrors);

    JMenuItem visGrph = new JMenuItem("Visualize tree");
    if (grph != null) {
  if(((Drawable)temp_classifier).graphType()==Drawable.TREE) {
      visGrph.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
      String title;
      if (vp != null) title = vp.getName();
      else title = selectedName;
      visualizeTree(grph, title);
        }
    });
  }
  else if(((Drawable)temp_classifier).graphType()==Drawable.BayesNet) {
      visGrph.setText("Visualize graph");
      visGrph.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
      Thread th = new Thread() {
        public void run() {
        visualizeBayesNet(grph, selectedName);
        }
          };
      th.start();
        }
    });
  }
  else
      visGrph.setEnabled(false);
    } else {
      visGrph.setEnabled(false);
    }
    resultListMenu.add(visGrph);

    JMenuItem visMargin = new JMenuItem("Visualize margin curve");
    if ((preds != null) && (classAtt != null) && (classAtt.isNominal())) {
      visMargin.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      try {
        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);
                }
               
View Full Code Here

  outBuff.append("\n=== Classifier model ===\n\n");
  outBuff.append(classifier.toString() + "\n");
 
  m_History.addResult(name, outBuff);
  m_History.setSingle(name);
  FastVector vv = new FastVector();
  vv.addElement(classifier);
  if (trainHeader != null) vv.addElement(trainHeader);
  // allow visualization of graphable classifiers
  String grph = null;
  if (classifier instanceof Drawable) {
    try {
      grph = ((Drawable)classifier).graph();
    } catch (Exception ex) {
    }
  }
  if (grph != null) vv.addElement(grph);
 
  m_History.addObject(name, vv);
      }
    }
  }
View Full Code Here

                    } catch (Exception ex) {
                    }
                  }

                  if (saveVis) {
                    FastVector vv = new FastVector();
                    vv.addElement(classifier);
                    if (trainHeader != null) vv.addElement(trainHeader);
                    vv.addElement(m_CurrentVis);
                    if (grph != null) {
                      vv.addElement(grph);
                    }
                    if ((eval != null) && (eval.predictions() != null)) {
                      vv.addElement(eval.predictions());
                      vv.addElement(userTestStructure.classAttribute());
                    }
                    m_History.addObject(name, vv);
                  } else {
                    FastVector vv = new FastVector();
                    vv.addElement(classifierToUse);
                    if (trainHeader != null) vv.addElement(trainHeader);
                    m_History.addObject(name, vv);
                  }
                }
              } catch (Exception ex) {
                ex.printStackTrace();
View Full Code Here

          requestedPopSize == m_totalPopPrevious) {
        return false;
      }
     
      // First construct some Instances for the curve
      FastVector fv = new FastVector();
      fv.addElement(new Attribute("Sample Size"));
      fv.addElement(new Attribute("Cost/Benefit"));
      Instances costBenefitI = new Instances("Cost/Benefit Curve", fv, 100);
     
      // process the performance data to make this curve
      Instances performanceI = m_masterPlot.getPlotInstances();
     
View Full Code Here

        m_sValue = sValue;
        m_att = m_Instances.attribute(nTargetNode);
        SerializedObject so = new SerializedObject(m_Distributions[nTargetNode]);
        m_CPT = (Estimator[]) so.getObject();
        ;
        m_children = new FastVector();
        for (int iNode = 0; iNode < getNrOfNodes(); iNode++) {
          if (m_ParentSets[iNode].contains(nTargetNode)) {
            m_children.addElement(iNode);
          }
        }
View Full Code Here

    FastVector m_posX;

    FastVector m_posY;

    alignAction(FastVector nodes) {
      m_nodes = new FastVector(nodes.size());
      m_posX = new FastVector(nodes.size());
      m_posY = new FastVector(nodes.size());
      for (int iNode = 0; iNode < nodes.size(); iNode++) {
        int nNode = (Integer) nodes.elementAt(iNode);
        m_nodes.addElement(nNode);
        m_posX.addElement(getPositionX(nNode));
        m_posY.addElement(getPositionY(nNode));
View Full Code Here

    FastVector m_nodes;
    int m_dX;
    int m_dY;

    SetGroupPositionAction(FastVector nodes, int dX, int dY) {
      m_nodes = new FastVector(nodes.size());
      for (int iNode = 0; iNode < nodes.size(); iNode++) {
        m_nodes.addElement(nodes.elementAt(iNode));
      }
      m_dX = dX;
      m_dY = dY;
View Full Code Here

    FastVector m_nPosY;
    FastVector m_nPosX2;
    FastVector m_nPosY2;

    LayoutGraphAction(FastVector nPosX, FastVector nPosY) {
      m_nPosX = new FastVector(nPosX.size());
      m_nPosY = new FastVector(nPosX.size());
      m_nPosX2 = new FastVector(nPosX.size());
      m_nPosY2 = new FastVector(nPosX.size());
      for (int iNode = 0; iNode < nPosX.size(); iNode++) {
        m_nPosX.addElement(m_nPositionX.elementAt(iNode));
        m_nPosY.addElement(m_nPositionY.elementAt(iNode));
        m_nPosX2.addElement(nPosX.elementAt(iNode));
        m_nPosY2.addElement(nPosY.elementAt(iNode));
View Full Code Here

   *
   * @return the header
   */
  private Instances makeHeader() {

    FastVector fv = new FastVector();
    fv.addElement(new Attribute(TRUE_POS_NAME));
    fv.addElement(new Attribute(FALSE_NEG_NAME));
    fv.addElement(new Attribute(FALSE_POS_NAME));
    fv.addElement(new Attribute(TRUE_NEG_NAME));
    fv.addElement(new Attribute(FP_RATE_NAME));
    fv.addElement(new Attribute(TP_RATE_NAME));
    fv.addElement(new Attribute(PRECISION_NAME));
    fv.addElement(new Attribute(RECALL_NAME));
    fv.addElement(new Attribute(FALLOUT_NAME));
    fv.addElement(new Attribute(FMEASURE_NAME));
    fv.addElement(new Attribute(SAMPLE_SIZE_NAME));
    fv.addElement(new Attribute(LIFT_NAME));
    fv.addElement(new Attribute(THRESHOLD_NAME));     
    return new Instances(RELATION_NAME, fv, 100);
  }
View Full Code Here

TOP

Related Classes of weka.core.FastVector$FastVectorEnumeration

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.