贝叶斯 classifier 程序使用 Jtable 预测 java 中给定信息的 class

Bayes classifier program to predict the class of give information in java using Jtable

使用以下参数预测人员工作类型的朴素贝叶斯程序:年龄:30,学历:MTech,经验:8..

    WorkType       Age     Qualication     Experience

   Consultancy     30       Ph.D.             9
    Service        21       MTech.            1
    Research       26       MTech.            2
    Service        28       BTech.            10
    Consultancy    40       MTech.            14
    Research       35       Ph.D.             10
    Research       27       BTech.             6
    Service        32       MTech.             9
    Consultancy    45       Btech.            17
    Research       36       Ph.D.              7

    package try2;
    import java.awt.BorderLayout;

    import javax.swing.*;

    public class bayes  
    {
        JFrame frame;
        JTable table;
        JPanel panel;
        JScrollPane tableContainer;

        int i,j;
        int countC=0,countR=0,countS=0;
        int count=0;
        int[] CAge=new int[3];


        public bayes()
        {
              frame = new JFrame("JTable Test Display");

              panel = new JPanel();
              panel.setLayout(new BorderLayout());
             String row[][]={{"consultancy","30","phd","9"},  
                   {"service","21","mtech","1"}              ,
                {"research","26","mtech","2"},{"service","28","btech","10"},
                {"consultancy","40","mtech","14"},{"research","35","phd","10"},
                {"research","27","btech","6"},{"service","32","mtech","9"},
                {"consultancy","45","btech","17"},{"research","36","phd","7"}};

        String column[]={"job","age","qualification","experience"};
        table=new JTable(row,column);

         tableContainer = new JScrollPane(table);

        panel.add(tableContainer, BorderLayout.CENTER);
        frame.getContentPane().add(panel);

        frame.pack();
        frame.setVisible(true);



        //work type count
        for(i=0;i<10;i++)
        {
            if(table.getValueAt(i,0)=="consultancy")
            {
                countC++;
            }
            if(table.getValueAt(i,0)=="research")
            {
                countR++;
            }
            if(table.getValueAt(i,0)=="service")
            {
                countS++;
            }
        }


        //consultancy age count
        for(i=0;i<10;i++)

        {
  ***if(((table.getValueAt(i, 0))=="consultancy") && ((Integer.parseInt((String)table.getValueAt(i, 1))>=20) || (Integer.parseInt((String)table.getValueAt(i, 1))<=30)) )***
            {
              count++;  
            }

上面代码的问题是我无法比较年龄列值 numbers.I 尝试使用 intparse() 函数将值转换为 int 但仍然不是 working.the上面给定的行用 *** 标记 code.please 帮助 me.it 给出了无法将对象类型转换为整数的错误

可能问题出在条件:

((Integer.parseInt((String) table.getValueAt(i, 1)) >= 20) || (Integer.parseInt((String) table.getValueAt(i, 1)) <= 30))

此计算结果始终为真,因此计数不正确。如果你只想计算年龄在 20 到 30 岁之间的人,你应该使用 AND 运算符:

((Integer.parseInt((String) table.getValueAt(i, 1)) >= 20) && (Integer.parseInt((String) table.getValueAt(i, 1)) <= 30))