1

我正在使用 Encog(通过 Java)研究二进制分类器。我使用 SVM 或神经网络设置它,我想使用(部分)ROC 曲线下的区域来评估不同模型的质量。

更具体地说,理想情况下,我希望将模型的输出转换为某种预测置信度分数,该分数可用于 ROC 中的排名排序,但我尚未在文档中找到任何内容。

在代码中,我得到的模型结果如下:

MLData result = ((MLRegression) method).compute( pair.getInput() );
String classification = normHelper.denormalizeOutputVectorToString( result )[0]; 

我如何获得分类的数值置信度?

4

2 回答 2

1

我找到了一种在 encog 框架内从 SVM 中哄骗预测概率的方法。此方法依赖于 libSVM 的 -b 选项的等效项(请参阅http://www.csie.ntu.edu.tw/~cjlin/libsvm/index.html

为此,请从 encog 覆盖 SVM 类。构造函数将通过 smv_parameter 对象启用概率估计(见下文)。然后,在进行计算时,调用 svm_predict_probability 方法,如下所示。

警告:下面只是一个代码片段,为了有用,您可能需要编写其他构造函数并将结果概率从下面的方法中传递出去。此片段基于 encog 版本 3.3.0。

public class MySVMProbability extends SVM {

public MySVMProbability(SVM method) {
    super(method.getInputCount(), method.getSVMType(), method.getKernelType());
    // Enable probability estimates 
    getParams().probability = 1;
}


@Override
public int classify(final MLData input) {
    svm_model model = getModel();
    if (model == null) {
        throw new EncogError(
                "Can't use the SVM yet, it has not been trained, " 
                + "and no model exists.");
    }

    final svm_node[] formattedInput = makeSparse(input);
    final double probs[] = new double[svm.svm_get_nr_class(getModel())];
    final double d = svm.svm_predict_probability(model, formattedInput, probs);

    /* probabilities for each class are in probs[] */

    return (int) d;
}


@Override
public MLData compute(MLData input) {
    svm_model model = getModel();
    if (model == null) {
        throw new EncogError(
                "Can't use the SVM yet, it has not been trained, "
                + "and no model exists.");
    }

    final MLData result = new BasicMLData(1);

    final svm_node[] formattedInput = makeSparse(input);

    final double probs[] = new double[svm.svm_get_nr_class(getModel())];
    final double d = svm.svm_predict_probability(model, formattedInput, probs);
    /* probabilities for each class are in probs[] */
    result.setData(0, d);

    return result;
}
}
于 2014-12-17T15:30:10.163 回答
0

Encog 没有直接支持 ROC 曲线。ROC 曲线更像是一种可视化而不是实际的模型类型,这主要是 Encog 的重点。

为 SVM 和神经网络生成 ROC 曲线有些不同。对于神经网络,您必须为分类神经元建立阈值。这里有一篇很好的论文:http: //www.lcc.uma.es/~jja/recidiva/048.pdf

将来我可能最终会在 Encog 中添加对 ROC 曲线的直接支持。它们正在成为一种非常常见的可视化。

于 2014-12-13T04:43:20.000 回答