我正在开发一个使用Encog (通过Java)的二进制分类器。我使用支持向量机或神经网络建立了它,我想使用ROC曲线下的面积(部分)来评估不同模型的质量。
更具体地说,理想情况下,我希望将模型的输出转换为某种预测置信度分数,可用于ROC中的排名排序,但我尚未在文档中找到任何内容。
在代码中,我得到的模型结果如下:
MLData result = ((MLRegression) method).compute( pair.getInput() );
String classification = normHelper.denormalizeOutputVectorToString( result )[0];
如何获得分类的数值置信度?
发布于 2014-12-17 15:30:10
我已经找到了一种在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-13 04:43:20
Encog不直接支持ROC曲线。ROC曲线更多地是一种可视化,而不是实际的模型类型,这是Encog的主要关注点。
为支持向量机和神经网络生成ROC曲线略有不同。对于神经网络,您必须为分类神经元建立阈值。这里有一篇关于这方面的好论文:http://www.lcc.uma.es/~jja/recidiva/048.pdf
我可能最终会在将来在Encog中添加对ROC曲线的直接支持。它们正在成为一种非常常见的可视化。
https://stackoverflow.com/questions/27432691
复制