gpt4 book ai didi

java - 使用 Jtable 预测 Java 中给定信息的类别的贝叶斯分类器程序

转载 作者:行者123 更新时间:2023-12-01 11:09:37 27 4
gpt4 key购买 nike

朴素贝叶斯程序可预测具有以下参数的人的工作类型:年龄: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++;
}

上面代码的问题是我无法将年龄列值与数字进行比较。我尝试使用 intparse() 函数将值转换为 int,但仍然不起作用。该行标记为 ** * 在上面给出的代码中。请帮助我。它给出错误,它无法将对象类型转换为整数

最佳答案

也许问题出在以下情况:

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

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

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

关于java - 使用 Jtable 预测 Java 中给定信息的类别的贝叶斯分类器程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32527042/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com