【问题标题】:WEKA: how to get the score from classifyInstance?WEKA:如何从分类实例中获得分数?
【发布时间】:2011-07-30 14:50:37
【问题描述】:

我正在使用 FilteredClassifier.classifyInstance() 对 weka 中的实例进行分类。

我有 2 个类(真假)并且我有很多正面,所以我实际上需要知道每个实例的分数才能获得最好的正面。

你知道我如何从我的 weka 分类器中获得分数吗?

谢谢

更新:我也尝试过使用 distributionForInstance,但对于每个实例,我总是得到一个 [1.0, 0.0] 的数组。

我实际上需要比较几个实例,看看哪个最可靠,哪个有更多变化才能正确分类。

【问题讨论】:

    标签: weka


    【解决方案1】:

    distributionForInstance(Instance anInstance) 是您需要的方法。它为您提供了一个 Double 数组,显示了您对每个课程的信心。我正在使用 Weka 3.6。它对我很有效。如果你总是得到相同的值,那么你的分类器就没有得到很好的训练,而且根本没有判别力。在这种情况下,你应该总是得到相同的预测类。你平衡了你的训练集吗?

    【讨论】:

      【解决方案2】:

      distributionForInstance(Instance anInstance) 似乎是对的。

      也许它不适合您,因为分类器不知道您需要置信度值?例如,对于 Weka Java 上的 LibSVM,您需要将 setProbabilityEstimates 设置为 true,才能使用分数。

      【讨论】:

        【解决方案3】:

        对数据运行分类器后,您可以通过右键单击“结果列表”中的测试来可视化数据。此右键菜单上有许多其他功能,可让您从 weka 获得分数分类器。

        【讨论】:

        • 我使用的是 Java API 而不是 GUI。这是我使用的方法 FilteredClassifier.classifyInstance()
        【解决方案4】:

        假设您的模型已经过训练。

        然后,您可以使用 distributionForInstance 进行预测。此命令生成一个由两项组成的数组(因为您的数据集上有两个类:true 和 false)

        double[] distributions = model.distributionForInstance(new_instance);
        

        之后,distributions数组中最大项的索引就是分类结果。

        假设分布 = {0.9638458988630731, 0.03615410113692686}。在这种情况下,您的新实例将被归类为 class_0,因为第一项大于分布数组中的第二项。

        你也可以通过classifyInstance命令获取这个索引。

        double classifiedIndex = model.classifyInstance(new_instance);
        

        对于分布 = {0.9638458988630731, 0.03615410113692686},classifiedIndex 值将为 0。

        最后,您可以将类名作为真或假而不是类索引。

        new_instance.setClassValue(classifiedIndex); //firstly, assigned classified index to new_instance.
        String classifiedText = new_instance.stringValue(new_instance.numAttributes());
        

        此代码块产生错误。

        您可以检查此GitHub project 的回归和分类。

        【讨论】:

          猜你喜欢
          • 2014-01-27
          • 2012-03-25
          • 2013-05-13
          • 2012-06-30
          • 2015-02-01
          • 2011-09-07
          • 2011-12-10
          • 2019-03-31
          • 2015-07-16
          相关资源
          最近更新 更多