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

📄 beiyesiframe.java

📁 本系统是一个简单的朴素贝叶斯的数据集分类系统,能够通过输入数据并预测数据集属于哪一个类
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
import java.util.*;

import java.awt.event.*;

class BeiyesiFrame extends JFrame implements ActionListener
{
	private JPanel aPanel = new JPanel();//生成一个面板
	private JLabel aLabel;
	private JButton trainButton;//训练按钮
	private JButton enterButton;//确定按钮
	private JButton clearButton;//清空按钮
	private JLabel trainLabel = new JLabel();//显示是否训练成功
	private JLabel resultLabel = new JLabel();//显示结果
	private TextField inputField = new TextField();//输入数据
	SaveArray aArray = new SaveArray("aa.doc");
    SaveArray bArray = new SaveArray("cc.txt");
    //ExcutePossibility aClass= new ExcutePossibility(input);
    //ExcutePossibility bClass= new ExcutePossibility(input);
    
	public BeiyesiFrame()
	{
		setTitle("基于朴素贝叶斯的数据集分类");
		setupGUI();
	}
	
	public void setupGUI()
	{
		setSize(400,300);
		setLocation(100,20);
		Container conten = this.getContentPane();
		
	    conten.add(aPanel);
	    
	    setupPanel();
	}
	
	public void setupPanel()
	{
		aPanel.setLayout(null);
		
		aLabel = new JLabel("欢迎使用数据集分类器");
		aLabel.setSize(200,30);
		aLabel.setLocation(100,20);
		aPanel.add(aLabel);
		
		trainButton = new JButton("训练");
		trainButton.setSize(80,30);
		trainButton.setLocation(20,70);
		aPanel.add(trainButton);
		trainButton.addActionListener(this);
		
		trainLabel.setSize(280,30);
		trainLabel.setLocation(110,70);
		aPanel.add(trainLabel);
		
		inputField.setSize(330,30);
		inputField.setLocation(20,110);
		aPanel.add(inputField);
		
		enterButton = new JButton("确定");
		enterButton.setSize(80,30);
		enterButton.setLocation(150,150);
		aPanel.add(enterButton);
		enterButton.addActionListener(this);
		
		clearButton = new JButton("清空");
		clearButton.setSize(80,30);
		clearButton.setLocation(250,150);
		aPanel.add(clearButton);
		clearButton.addActionListener(this);
		
		resultLabel.setSize(200,30);
		resultLabel.setLocation(20,200);
		aPanel.add(resultLabel);
	}
	//String inputField.getText() = inputField.getText();		
	
	public void actionPerformed(ActionEvent event)
	{
		//aArray.excutemiu();
		//bArray.excutemiu();
		//System.out.println(input);
		int newcount=0;
        StringTokenizer token = new StringTokenizer(inputField.getText(),",");
		while(token.hasMoreTokens())
		{
			token.nextToken();
			newcount++;
		}
		//while
		double a[] =aArray.excute();
        double b[]=aArray.excutemiu();
	    ExcutePossibility aClass= new ExcutePossibility(inputField.getText());
	    ExcutePossibility bClass= new ExcutePossibility(inputField.getText());
       	    
		if(event.getSource()==trainButton)
		{
			if(aArray.getpanduan()==true)
			{
				trainLabel.setText("训练成功完成,请输入8个数据(以逗号隔开)");
			}
		}
		else if(event.getSource()==enterButton)
		{
			/*if(newcount==aArray.getCount())
            {
        		System.out.println("属于aa.doc的概率为--"+aClass.possibility(a,b));       
        		System.out.println("属于cc.txt的概率为@@"+bClass.possibility(bArray.excute(),bArray.excutemiu()));
            }
            else
        		System.out.println("属于aa.doc的概率为50%\n属于cc.txt的概率也为50%");
        		//if
        	*/	
			if(inputField.getText().equals(""))
			{
				resultLabel.setText("您未输入数据或者不属于任何类");				
			}
			else if(newcount==aArray.getCount()&&aClass.possibility(a,b)<bClass.possibility(bArray.excute(),bArray.excutemiu()))
			{
				resultLabel.setText("您输入的新数据更可能属于aa.doc");
			}
		    else if(newcount==aArray.getCount()&&aClass.possibility(a,b)>bClass.possibility(bArray.excute(),bArray.excutemiu()))
		    {
		    	resultLabel.setText("您输入的新数据更可能属于cc.txt");
		    }
		    else
		    {
		    	resultLabel.setText("The input doesn't belong to any");
		    }
			
		}
		else if(event.getSource()==clearButton)
		{
			resultLabel.setText("");
			inputField.setText("");
		}
	}
}

⌨️ 快捷键说明

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