Java中的成本矩阵

时间:2014-11-20 13:45:31

标签: java weka

我需要使用Weka API在Java Eclipse编辑器中实现Cost Matrix。我已经在Jave中导入了所有Weka API并使用了代码: -

public class EvaluteCM {
public static void main(String[] args) throws Exception {
 CostMatrix matrix = new CostMatrix(
                       new BufferedReader(new FileReader("c:/data.txt")));
 System.out.println(matrix);
 }
}

我在这里显示了我在文本文件data.txt

中的一些数据
0.211429    0.223573    0.274898    0.260206    0   class1
0.211429    0.223573    0.274898    0.260206    0   class1
0.099854    0.110879    0.312785    0.291716    0   class1
0.747867    0   0.272726    0.320873    0.727273    class2
0.775455    0   0.272726    0.304774    0.727273    class2
0.775455    0   0.272726    0.304774    0.727273    class2
0.76761 0   0.272726    0.304774    0.727273    class2

当我实现EvaluteCM类时,我收到以下错误

   Exception in thread "main" java.lang.NumberFormatException: For input string: "0.211429"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at weka.classifiers.CostMatrix.<init>(CostMatrix.java:524)
at EvaluteCM.main(EvaluteCM.java:13)

任何帮助将不胜感激?

1 个答案:

答案 0 :(得分:1)

您将数据文件作为CostMatrix提供。 CostMatrix文件应如下所示,取自weka wiki。请参阅Cost Matrix Weka Wiki。它提供了更好的例子作为matlab文件

费用矩阵的格式

定期

 % Rows    Columns
 2    2
 % Matrix elements
 0.0    5.0
 1.0    0.0

Matlab单行格式

 [0.0 5.0; 1.0 0.0]
相关问题