⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 attributeselectionpanel.java

📁 Java 编写的多种数据挖掘算法 包括聚类、分类、预处理等
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
      public void actionPerformed(ActionEvent e) {	stopAttributeSelection();      }    });        m_History.setHandleRightClicks(false);    // see if we can popup a menu for the selected result    m_History.getList().addMouseListener(new MouseAdapter() {	public void mouseClicked(MouseEvent e) {	  if (((e.getModifiers() & InputEvent.BUTTON1_MASK)	       != InputEvent.BUTTON1_MASK) || e.isAltDown()) {	    int index = m_History.getList().locationToIndex(e.getPoint());	    if (index != -1) {	      String name = m_History.getNameAtIndex(index);	      visualize(name, e.getX(), e.getY());	    } else {	      visualize(null, e.getX(), e.getY());	    }	  }	}      });    // Layout the GUI    JPanel p1 = new JPanel();    p1.setBorder(BorderFactory.createCompoundBorder(		 BorderFactory.createTitledBorder("Attribute Evaluator"),		 BorderFactory.createEmptyBorder(0, 5, 5, 5)		 ));    p1.setLayout(new BorderLayout());    p1.add(m_AEEPanel, BorderLayout.NORTH);    JPanel p1_1 = new JPanel();    p1_1.setBorder(BorderFactory.createCompoundBorder(		 BorderFactory.createTitledBorder("Search Method"),		 BorderFactory.createEmptyBorder(0, 5, 5, 5)		 ));    p1_1.setLayout(new BorderLayout());    p1_1.add(m_ASEPanel, BorderLayout.NORTH);    JPanel p_new = new JPanel();    p_new.setLayout(new BorderLayout());    p_new.add(p1, BorderLayout.NORTH);    p_new.add(p1_1, BorderLayout.CENTER);    JPanel p2 = new JPanel();    GridBagLayout gbL = new GridBagLayout();    p2.setLayout(gbL);    p2.setBorder(BorderFactory.createCompoundBorder(		 BorderFactory.createTitledBorder("Attribute Selection Mode"),		 BorderFactory.createEmptyBorder(0, 5, 5, 5)		 ));    GridBagConstraints gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.WEST;    gbC.gridy = 2;     gbC.gridx = 0;    gbL.setConstraints(m_TrainBut, gbC);    p2.add(m_TrainBut);    gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.WEST;    gbC.gridy = 4;     gbC.gridx = 0;    gbL.setConstraints(m_CVBut, gbC);    p2.add(m_CVBut);    gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.EAST;    gbC.fill = GridBagConstraints.HORIZONTAL;    gbC.gridy = 4;     gbC.gridx = 1;    gbC.insets = new Insets(2, 10, 2, 10);    gbL.setConstraints(m_CVLab, gbC);    p2.add(m_CVLab);    gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.EAST;    gbC.fill = GridBagConstraints.HORIZONTAL;    gbC.gridy = 4;     gbC.gridx = 2;  gbC.weightx = 100;    gbC.ipadx = 20;    gbL.setConstraints(m_CVText, gbC);    p2.add(m_CVText);    gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.EAST;    gbC.fill = GridBagConstraints.HORIZONTAL;    gbC.gridy = 6;     gbC.gridx = 1;    gbC.insets = new Insets(2, 10, 2, 10);    gbL.setConstraints(m_SeedLab, gbC);    p2.add(m_SeedLab);    gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.EAST;    gbC.fill = GridBagConstraints.HORIZONTAL;    gbC.gridy = 6;     gbC.gridx = 2;  gbC.weightx = 100;    gbC.ipadx = 20;    gbL.setConstraints(m_SeedText, gbC);    p2.add(m_SeedText);    JPanel buttons = new JPanel();    buttons.setLayout(new GridLayout(2, 2));    buttons.add(m_ClassCombo);    m_ClassCombo.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));    JPanel ssButs = new JPanel();    ssButs.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));    ssButs.setLayout(new GridLayout(1, 2, 5, 5));    ssButs.add(m_StartBut);    ssButs.add(m_StopBut);    buttons.add(ssButs);        JPanel p3 = new JPanel();    p3.setBorder(BorderFactory.		 createTitledBorder("Attribute selection output"));    p3.setLayout(new BorderLayout());    final JScrollPane js = new JScrollPane(m_OutText);    p3.add(js, BorderLayout.CENTER);    js.getViewport().addChangeListener(new ChangeListener() {      private int lastHeight;      public void stateChanged(ChangeEvent e) {	JViewport vp = (JViewport)e.getSource();	int h = vp.getViewSize().height; 	if (h != lastHeight) { // i.e. an addition not just a user scrolling	  lastHeight = h;	  int x = h - vp.getExtentSize().height;	  vp.setViewPosition(new Point(0, x));	}      }    });    JPanel mondo = new JPanel();    gbL = new GridBagLayout();    mondo.setLayout(gbL);    gbC = new GridBagConstraints();    gbC.fill = GridBagConstraints.HORIZONTAL;    gbC.gridy = 0;     gbC.gridx = 0; gbC.weightx = 0;    gbL.setConstraints(p2, gbC);    mondo.add(p2);    gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.NORTH;    gbC.fill = GridBagConstraints.HORIZONTAL;    gbC.gridy = 1;     gbC.gridx = 0; gbC.weightx = 0;    gbL.setConstraints(buttons, gbC);    mondo.add(buttons);    gbC = new GridBagConstraints();    gbC.fill = GridBagConstraints.BOTH;    gbC.gridy = 2;     gbC.gridx = 0; gbC.weightx = 0; gbC.weighty = 100;    gbL.setConstraints(m_History, gbC);    mondo.add(m_History);    gbC = new GridBagConstraints();    gbC.fill = GridBagConstraints.BOTH;    gbC.gridy = 0;     gbC.gridx = 1;    gbC.gridheight = 3;    gbC.weightx = 100; gbC.weighty = 100;    gbL.setConstraints(p3, gbC);    mondo.add(p3);    setLayout(new BorderLayout());    add(p_new, BorderLayout.NORTH);    add(mondo, BorderLayout.CENTER);  }    /**   * Updates the enabled status of the input fields and labels.   */  protected void updateRadioLinks() {    m_CVBut.setEnabled(true);    m_CVText.setEnabled(m_CVBut.isSelected());    m_CVLab.setEnabled(m_CVBut.isSelected());    m_SeedText.setEnabled(m_CVBut.isSelected());    m_SeedLab.setEnabled(m_CVBut.isSelected());        if (m_AttributeEvaluatorEditor.getValue() 	instanceof AttributeTransformer) {      m_CVBut.setSelected(false);      m_CVBut.setEnabled(false);      m_CVText.setEnabled(false);      m_CVLab.setEnabled(false);      m_SeedText.setEnabled(false);      m_SeedLab.setEnabled(false);      m_TrainBut.setSelected(true);    }  }    /**   * Sets the Logger to receive informational messages   *   * @param newLog the Logger that will now get info messages   */  public void setLog(Logger newLog) {    m_Log = newLog;  }    /**   * Tells the panel to use a new set of instances.   *   * @param inst a set of Instances   */  public void setInstances(Instances inst) {        m_Instances = inst;    String [] attribNames = new String [m_Instances.numAttributes()];    for (int i = 0; i < attribNames.length; i++) {      String type = "";      switch (m_Instances.attribute(i).type()) {      case Attribute.NOMINAL:	type = "(Nom) ";	break;      case Attribute.NUMERIC:	type = "(Num) ";	break;      case Attribute.STRING:	type = "(Str) ";	break;      case Attribute.DATE:	type = "(Dat) ";	break;      case Attribute.RELATIONAL:	type = "(Rel) ";	break;      default:	type = "(???) ";      }      String attnm = m_Instances.attribute(i).name();           attribNames[i] = type + attnm;    }    m_StartBut.setEnabled(m_RunThread == null);    m_StopBut.setEnabled(m_RunThread != null);    m_ClassCombo.setModel(new DefaultComboBoxModel(attribNames));    m_ClassCombo.setSelectedIndex(attribNames.length - 1);    m_ClassCombo.setEnabled(true);  }    /**   * Starts running the currently configured attribute evaluator and   * search method. This is run in a separate thread, and will only start if   * there is no attribute selection  already running. The attribute selection   * output is sent to the results history panel.   */  protected void startAttributeSelection() {    if (m_RunThread == null) {      m_StartBut.setEnabled(false);      m_StopBut.setEnabled(true);      m_RunThread = new Thread() {	public void run() {	  // Copy the current state of things	  m_Log.statusMessage("Setting up...");	  Instances inst = new Instances(m_Instances);	  int testMode = 0;	  int numFolds = 10;	  int seed = 1;	  int classIndex = m_ClassCombo.getSelectedIndex();	  ASEvaluation evaluator = 	     (ASEvaluation) m_AttributeEvaluatorEditor.getValue();	  ASSearch search = (ASSearch) m_AttributeSearchEditor.getValue();	  StringBuffer outBuff = new StringBuffer();	  String name = (new SimpleDateFormat("HH:mm:ss - "))	  .format(new Date());	  String sname = search.getClass().getName();	  if (sname.startsWith("weka.attributeSelection.")) {	    name += sname.substring("weka.attributeSelection.".length());	  } else {	    name += sname;	  }	  String ename = evaluator.getClass().getName();	  if (ename.startsWith("weka.attributeSelection.")) {	    name += (" + "		     +ename.substring("weka.attributeSelection.".length()));	  } else {	    name += (" + "+ename);	  }	  AttributeSelection eval = null;	  try {	    if (m_CVBut.isSelected()) {	      testMode = 1;	      numFolds = Integer.parseInt(m_CVText.getText());	      seed = Integer.parseInt(m_SeedText.getText());	      if (numFolds <= 1) {		throw new Exception("Number of folds must be greater than 1");	      }	    } 	    inst.setClassIndex(classIndex);	    // Output some header information	    m_Log.logMessage("Started " + ename);	    if (m_Log instanceof TaskLogger) {	      ((TaskLogger)m_Log).taskStarted();	    }	    outBuff.append("=== Run information ===\n\n");	    outBuff.append("Evaluator:    " + ename);	    if (evaluator instanceof OptionHandler) {	      String [] o = ((OptionHandler) evaluator).getOptions();	      outBuff.append(" " + Utils.joinOptions(o));	    }	    outBuff.append("\nSearch:       " + sname);	    if (search instanceof OptionHandler) {	      String [] o = ((OptionHandler) search).getOptions();	      outBuff.append(" " + Utils.joinOptions(o));	    }	    outBuff.append("\n");	    outBuff.append("Relation:     " + inst.relationName() + '\n');	    outBuff.append("Instances:    " + inst.numInstances() + '\n');	    outBuff.append("Attributes:   " + inst.numAttributes() + '\n');	    if (inst.numAttributes() < 100) {	      for (int i = 0; i < inst.numAttributes(); i++) {		outBuff.append("              " + inst.attribute(i).name()			       + '\n');	      }	    } else {	      outBuff.append("              [list of attributes omitted]\n");	    }	    outBuff.append("Evaluation mode:    ");	    switch (testMode) {	      case 0: // select using all training	      outBuff.append("evaluate on all training data\n");	      break;	      case 1: // CV mode	      outBuff.append("" + numFolds + "-fold cross-validation\n");	      break;	    }	    outBuff.append("\n");	    m_History.addResult(name, outBuff);	    m_History.setSingle(name);	    	    // Do the feature selection and output the results.	    m_Log.statusMessage("Doing feature selection...");	    m_History.updateResult(name);	    	    eval = new AttributeSelection();	    eval.setEvaluator(evaluator);	    eval.setSearch(search);	    eval.setFolds(numFolds);	    eval.setSeed(seed);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -