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

📄 mainapp.java

📁 ID3决策树算法的JAVA实现:ID3算法是机器学习中的一种分类方法
💻 JAVA
字号:
package dsstree;import javax.swing.*;import java.sql.*;import com.borland.jbcl.layout.*;import java.awt.*;public class mainApp extends JFrame{  JLabel jLabel1 = new JLabel();  static JTextArea text = new JTextArea();  JScrollPane jScrollPane1 = new JScrollPane();  static JScrollPane scrollPane = new JScrollPane();  XYLayout xYLayout1 = new XYLayout();  static JTextField result = new JTextField();  public mainApp()  {    //super("ID3算法的应用-决策树  制作:朱付保");    super("基于ID3算法的决策树应用与实现");    //setSize(665,560);    setSize(500,400);    setVisible(true);    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }    this.show();  }  private void jbInit() throws Exception {    jLabel1.setAlignmentX((float) 0.0);    jLabel1.setAlignmentY((float) 0.5);    jLabel1.setMaximumSize(new Dimension(77, 16));    jLabel1.setText("试验结果信息");    this.getContentPane().setLayout(xYLayout1);    text.setAlignmentX((float) 0.5);    text.setAlignmentY((float) 0.5);    text.setMaximumSize(new Dimension(800, 600));    text.setMinimumSize(new Dimension(640, 480));    text.setText("jTextArea1");    this.setDefaultCloseOperation(HIDE_ON_CLOSE);    this.setForeground(Color.black);    this.setLocale(java.util.Locale.getDefault());    scrollPane.setMaximumSize(new Dimension(32767, 32767));    jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);    xYLayout1.setWidth(546);    xYLayout1.setHeight(475);    result.setFont(new java.awt.Font("Dialog", 1, 16));    result.setForeground(Color.blue);    result.setText("select leaf node!");    this.getContentPane().add(jScrollPane1,           new XYConstraints(12, 32, 287, 395));    this.getContentPane().add(jLabel1,        new XYConstraints(12, 9, 109, 23));    this.getContentPane().add(scrollPane,    new XYConstraints(311, 32, 223, 395));    this.getContentPane().add(result,     new XYConstraints(12, 435, 522, 27));    jScrollPane1.getViewport().add(text, null);  }  public static void main(String[] args)  {    mainApp mainApp = new mainApp();    dssTree theTree;    TreeNode root;    Connection con = null;    Statement stmt = null;    int[][] data = new int[80][6];    int row = 0; //record the row of the data in caselib of talk    int col = 6;    int[] att_No = new int[col];    String[] att_Name = new String[col];    att_No[1] = 5;    att_No[2] = 3;    att_No[3] = 4;    att_No[4] = 3;    att_No[5] = 3;    att_Name[1] = "r";    att_Name[2] = "p";    att_Name[3] = "d";    att_Name[4] = "g";    att_Name[5] = "t";    //read the data in caselib of talk////////////////////////    try {      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");    }    catch (ClassNotFoundException e) {}    try {      String pSql = "select * from caselib";      con = DriverManager.getConnection("jdbc:odbc:mydb");      stmt = con.createStatement();      ResultSet rs = stmt.executeQuery(pSql);      while (rs.next()) {        data[row][0] = rs.getInt("rebate");        data[row][1] = rs.getInt("payment");        data[row][2] = rs.getInt("delivery");        data[row][3] = rs.getInt("gift");        data[row][4] = rs.getInt("timelimit");        data[row][5] = rs.getInt("np");        row++;      }      con.close();    }    catch (SQLException ee) {}    //Disply the data on the screen ////////////////////////    text.setText("案例库中案例个数:"+row);    text.append("\nr:商品折扣");    text.append("\np:付款方式");    text.append("\nd:送货方式");    text.append("\ng:礼品回赠");    text.append("\nt:交货时限");    text.append("\nnp:正例或反例");    text.append("\nNo.  r  p  d  g  t  np");    text.append("\n----------------------\n");    for (int i = 0; i < row; i++) {      String order = "";      if (i < 9)        order = "0";        text.append(order+(i+1)+":");      for (int j = 0; j < col; j++) {        text.append("  "+data[i][j]+"");      }      text.append("\n");;    }    ///////////////////////////////////////////////////////    text.append("\nCreating the dssTree,Please wait...");    theTree = new dssTree(data, row, col, att_No, att_Name);    text.append("\nCreating dssTree Successfully!");    root = theTree.getRoot();    text.append("\nthe information of each TreeNode in the dssTree");    theTree.preOrderAllNodes(root);    text.append("\nthe rules of each leafNode");    theTree.preOrderRules(root);    theTree.layerOrderToGenTree(root);    text.append("\n==============");    text.append("\nThank you!");  }}

⌨️ 快捷键说明

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