程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了删除 Weka ML 模型的测试 ARFF 文件中的最后一个类属性在预测模型中不起作用大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决删除 Weka ML 模型的测试 ARFF 文件中的最后一个类属性在预测模型中不起作用?

开发过程中遇到删除 Weka ML 模型的测试 ARFF 文件中的最后一个类属性在预测模型中不起作用的问题如何解决?下面主要结合日常开发的经验,给出你关于删除 Weka ML 模型的测试 ARFF 文件中的最后一个类属性在预测模型中不起作用的解决方法建议,希望对你解决删除 Weka ML 模型的测试 ARFF 文件中的最后一个类属性在预测模型中不起作用有所启发或帮助;

基本上,我正在用 Java (Weka) 构建一个机器学习模型来检测字符串中的一些模式。我有 2 个类属性,我试图让我的模型根据这些模式进行预测。当我将属性值保留在 ARFF 文件中时,我的代码有效,但当我将其取出并用测试文件中的问号替换时,我的代码就无效了。当我这样做时,它在输出中为我提供了所有相同的值 (cfb)。我知道模型不是硬编码的,但出于测试目的,我想删除这些属性值。我已经建立了分类器并评估了模型。

 /**
 * Make preDictions based on that model. Improve the model
 * 
 * @throws Exception
 */
public voID modelPreDictions(Instances TrainedDataSet,Instances testedDataSet,ClassifIEr classifIErTypE) throws Exception {
    // Get the number of classes
    int numClasses = TrainedDataSet.numClasses();
    // print out class values in the Training dataset
    for (int i = 0; i < numClasses; i++) {
        // get class String value using the class index
        String classvalue = TrainedDataSet.classAttribute().value(i);
        System.out.println("Class Value " + i + " is " + classvalue);
    }
    // set class index to the last attribute
    // loop through the new dataset and make preDictions
    System.out.println("===================");
    System.out.println("Actual Class,NB PreDicted");
    for (int i = 0; i < testedDataSet.numInstances(); i++) {
        // get class double value for current instance
        double actualClass = testedDataSet.instance(i).classvalue();
        // get class String value using the class index using the class's int value
        String actual = testedDataSet.classAttribute().value((int) actualClass);
        // get Instance object of current instance
        Instance newInst = testedDataSet.instance(i);
        // call classifyInstance,which returns a double value for the class
        double prednB = classifIErType.classifyInstance(newInst);
        // use this value to get String value of the preDicted class
        String predString = testedDataSet.classAttribute().value((int) prednB);
        System.out.println(actual + "," + predString);
    }
}

Image of the test ARFF File (Sorry,was getTing errors in pasTing the file content of the file.

解决方法

如果用问号替换测试集中的实际类,这些会被解释为缺失值。 Weka 中的缺失值由 Double.NaN 表示。将缺失值(即 Double.NaN)转换为 int 将导致 0,这是您的类的第一个名义值。您的实际课程将始终是第一个课程标签。

以下代码:

double missing = Utils.missingValue();
System.out.println("missing value as double: " + missing);
System.out.println("missing value as int: " + ((int) missing));

输出:

@H_122_5@missing value as double: NaN
missing value as int: 0

大佬总结

以上是大佬教程为你收集整理的删除 Weka ML 模型的测试 ARFF 文件中的最后一个类属性在预测模型中不起作用全部内容,希望文章能够帮你解决删除 Weka ML 模型的测试 ARFF 文件中的最后一个类属性在预测模型中不起作用所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。