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

📄 attributeevaluate.java

📁 基于weka平台的数据挖掘方法
💻 JAVA
字号:
import weka.gui.*;
import weka.core.*;
import weka.classifiers.*;
import weka.attributeSelection.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.io.*;

class attributeEvaluate extends JFrame{
	public static Object oo=new weka.attributeSelection.CfsSubsetEval();
	public static Object back_oo=null;
	public static Object so=new weka.attributeSelection.BestFirst();
	public static Object back_so=null;
	 final JTextField jtf1;
	 final JTextField jtf11;
	 JTextField jtf2,jtf3,jtf4,jtf5,jtf6;
	JPanel jp1,jp11,jp12,jp13,jp14,jp15,jp16,jp2,jp3,jp4,jp21,jp22,jp31,jp32;
	JLabel jl,jl1,jl2,jl3,jl4,jl5,jl6,jl7;
	JButton jb1,jb2,jb3,jb4;
	JButton jbchoose,jbchoose1;
	FileReader fd;
	FileWriter fw;
	String classmethod;
	
	attributeEvaluate(){
		super("SSiCP-First Step(Optional)");
		jl=new JLabel("Attribute Evaluator:               ");
		jbchoose=new JButton("Choose Evaluator");
		jtf1=new JTextField(oo.getClass().getName(),20);
		jl1=new JLabel("Search Method:                  ");
		jtf11=new JTextField(so.getClass().getName(),20);
		jbchoose1=new JButton("Choose Selector");
		
		jp1=new JPanel(new FlowLayout());
		jp11=new JPanel();
		jp12=new JPanel();
		jp13=new JPanel();
		jp14=new JPanel();
		jp15=new JPanel();
		jp16=new JPanel();
		jp2=new JPanel();
		jp3=new JPanel();
		jp4=new JPanel();
		jp21=new JPanel();
		jp22=new JPanel();
		jp31=new JPanel();
		jp32=new JPanel();
		jb1=new JButton("Generate");
		jb4=new JButton("Simple Calculate");
		jl2=new JLabel("input");
		jl3=new JLabel("output");
		jl4=new JLabel("Fold:");
		jl5=new JLabel("Random Seed:");
		jl6=new JLabel("Please Input the number you want to select:");
		jtf2=new JTextField(10);
		jtf3=new JTextField(10);
		jtf4=new JTextField("0",5);
		jtf5=new JTextField("1",3);
		jtf6=new JTextField("0",4);
		jb2=new JButton("input");
		jb3=new JButton("output");

		jbchoose.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e){
						back_oo=oo;						
						GenericObjectEditor ce = new GenericObjectEditor(true);
     					ce.setClassType(weka.attributeSelection.ASEvaluation.class);
  					    ce.setValue(oo);
   						PropertyDialog pd = new PropertyDialog(ce, 100, 100);
   						
   						((GenericObjectEditor.GOEPanel)ce.getCustomEditor()).addCancelListener(new ActionListener(){
   								public void actionPerformed(ActionEvent e){
		   							jtf1.setText(back_oo.getClass().getName());
		   							oo=back_oo;
   								}
   							});
   							
   						((GenericObjectEditor.GOEPanel)ce.getCustomEditor()).addOkListener(new ActionListener(){
   								public void actionPerformed(ActionEvent e){
   									jtf1.setText(oo.getClass().getName());	
   									back_oo=oo;   									
   								}
   							});
   							
   						ce.addPropertyChangeListener(new PropertyChangeListener(){
   								public void propertyChange(PropertyChangeEvent evt){
   										try {
   											GenericObjectEditor goe=(GenericObjectEditor)evt.getSource();
   											oo=goe.getValue();
										  }
										  catch (Exception ex) {
										  }
   								}
   							});
				}
			});


	jbchoose1.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e){
						back_so=so;						
						GenericObjectEditor ce = new GenericObjectEditor(true);
     					ce.setClassType(weka.attributeSelection.ASSearch.class);
     					ce.setValue(so);
   						PropertyDialog pd = new PropertyDialog(ce, 100, 100);
   						
   						((GenericObjectEditor.GOEPanel)ce.getCustomEditor()).addCancelListener(new ActionListener(){
   								public void actionPerformed(ActionEvent e){
		   							jtf11.setText(back_so.getClass().getName());
		   							so=back_so;
   								}
   							});
   							
   						((GenericObjectEditor.GOEPanel)ce.getCustomEditor()).addOkListener(new ActionListener(){
   								public void actionPerformed(ActionEvent e){
   									jtf11.setText(so.getClass().getName());	
   									back_so=so;  									
   								}
   							});
   							
   						ce.addPropertyChangeListener(new PropertyChangeListener(){
   								public void propertyChange(PropertyChangeEvent evt){
   										try {
   											GenericObjectEditor goe=(GenericObjectEditor)evt.getSource();
   											so=goe.getValue();
										  }
										  catch (Exception ex) {
										  }
   								}
   							});
				}
			});

		jb1.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e){
				try {				
					if(jtf2.getText().equals("") /*||  jtf3.getText().equals("") || ds.jcb1.getSelectedIndex()==0 || ds.jcb2.getSelectedIndex()==0 ||*//* jtf4.getText().equals("") || ds.jtf5.getText().equals("")*/){
						JOptionPane.showMessageDialog(null,"Some Information is Empty or not Select !","Warning",JOptionPane.INFORMATION_MESSAGE);
						return ;
					}
					fd=new FileReader(jtf2.getText());
					fw=null;
					if(!jtf3.getText().equals("")){
						fw=new FileWriter(jtf3.getText());
					}
				
					Instances insts=new Instances(fd);
					ASEvaluation asf=(ASEvaluation)oo;
					ASSearch ass=(ASSearch)so;
					insts.setClassIndex(0);
					asf.buildEvaluator(insts);
					int[] a=ass.search(asf,insts);
					new Thread(new DataSelect(insts,a)).start();
					Instances tmp=new Instances(insts);
					int numofinsts=Integer.parseInt(jtf6.getText());
					if(numofinsts==0 || numofinsts>=a.length){
						numofinsts=a.length;
					}
					int flag=0;
					for(int i=insts.numAttributes()-1;i>=1;i--){
						flag=0;
						for(int j=0;j<numofinsts;j++){
							if(i==a[j]){
								flag=1;
								break;
							}							  
						}
						if(flag==0)
							tmp.deleteAttributeAt(i);
					}
					if(fw!=null){
						fw.write(tmp.toString());
						fw.close();
					}
					fd.close();
				
			    }
			    catch (Exception ex) {
			   JOptionPane.showMessageDialog(null,"Evaluation or Selection is wrong");
			   if(oo.getClass().getName().equalsIgnoreCase("weka.attributeSelection.ConsistencySubsetEval")|| 
			   oo.getClass().getName().equalsIgnoreCase("weka.attributeSelection.ClassifierSubsetEval")||
			   oo.getClass().getName().equalsIgnoreCase("weka.attributeSelection.SymmetricalUncertAttributeSetEval")|| 
			   oo.getClass().getName().equalsIgnoreCase("weka.attributeSelection.WrapperSubsetEval"))
			   		so=new weka.attributeSelection.GreedyStepwise();
				else
			   		so=new weka.attributeSelection.Ranker();
			   	 	jtf11.setText(so.getClass().getName());	
			    }
			  }
			});

		setSize(600,500);
		setLocation(200,200);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setLayout(new GridLayout(2,2));
		getContentPane().add(jp1);
		getContentPane().add(jp2);
		getContentPane().add(jp3);
		getContentPane().add(jp4);
		jp1.add(jp11);
		jp1.add(jp12);
		jp1.add(jp13);
		jp1.add(jp14);
		jp1.add(jp15);
		jp1.add(jp16);
		jp11.add(jl);
		jp12.add(jtf1);
		jp13.add(jbchoose);
		jp14.add(jl1);
		jp15.add(jtf11);
		jp16.add(jbchoose1);
		jp21.add(jl2);
		jp21.add(jtf2);
		jp21.add(jb2);	
		jp22.add(jl3);
		jp22.add(jtf3);
		jp22.add(jb3);
		jp2.add(jp21);
		jp2.add(jp22);
		jp31.add(jl6);
		jp32.add(jtf6);
		jp3.add(jp31);
		jp3.add(jp32);
		jp4.add(jb1);
		jb2.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
				JFileChooser jfc=new JFileChooser();
				arffFileFilter ff=new arffFileFilter();
				jfc.setFileFilter(ff);
				jfc.showOpenDialog(null);
				File f=jfc.getSelectedFile();
				if(f!=null)
				jtf2.setText(f.getPath());
			}	
			
		});
		jb3.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
				JFileChooser jfc=new JFileChooser();
				arffFileFilter ff=new arffFileFilter();
				JFrame jf=(JFrame)((JButton)e.getSource()).getFocusCycleRootAncestor();
				jfc.setFileFilter(ff);
				if(jfc.showSaveDialog(null)==JFileChooser.APPROVE_OPTION)
				{
					File f=jfc.getSelectedFile();
					if(f.exists())
					{
						JDialog jd=new JDialog(jf,"Warning",true);
						JPanel jp1=new JPanel();
						JPanel jp2=new JPanel();
						JLabel id=new JLabel("File exist!");
						JButton jbtn=new JButton("I know");
						jp1.add(id);
						jp2.add(jbtn);
						jbtn.addActionListener(new ActionListener(){
							public void actionPerformed(ActionEvent e){
								((JDialog)((JButton)e.getSource()).getFocusCycleRootAncestor()).dispose();
							}
							});
						jd.add(jp1);
						jd.add(jp2,BorderLayout.SOUTH);
						jd.setLocation(300,300);
						jd.setSize(200,100);
						jd.setVisible(true);
						
					}
					String ss=f.getPath();
					if(!ss.toLowerCase().endsWith(".arff"))
						ss=ss+".arff";
					jtf3.setText(ss);
				}
			}	
			
		});		
		setVisible(true);

	}
	public static void main(String arg[]){
		new attributeEvaluate();
	}
	
}

⌨️ 快捷键说明

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