如何从MultilayerPerceptronClassifier获取分类概率? [英] How to get classification probabilities from MultilayerPerceptronClassifier?

查看:210
本文介绍了如何从MultilayerPerceptronClassifier获取分类概率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎与以下内容最相关:

This seems most related to: How to get the probability per instance in classifications models in spark.mllib

我正在用spark ml执行分类任务,构建了MultilayerPerceptronClassifier.建立模型后,我可以获得给定输入向量的预测类,但无法获得每个输出类的概率.上面的清单表明NaiveBayesModel从Spark 1.5.0

I'm doing a classification task with spark ml, building a MultilayerPerceptronClassifier. Once I build a model, I can get a predicted class given an input vector, but I can't get the probability for each output class. The above listing indicates that NaiveBayesModel supports this functionality as of Spark 1.5.0 (using a predictProbabilities method). I would like to get at this functionality for the MLPC. Is there a way I can hack at it to get my probabilities? Will it be included in 1.6.2?

推荐答案

如果您查看

If you take a look at this line in the MLPC source code, you can see that the MLPC is working from an underlying TopologyModel which provides the .predict method I'm looking for. The MLPC decodes the resulting Vector into a single label.

我能够使用训练有素的MLPC模型使用其权重来创建新的TopologyModel:

I'm able to use the trained MLPC model to create a new TopologyModel using its weights:

MultilayerPerceptronClassifier trainer = new MultilayerPerceptronClassifier()...;
MultilayerPerceptronClassificationModel model = trainer.fit(trainingData);
TopologyModel topoModel = FeedForwardTopology.multiLayerPerceptron(model.layers(), true).getInstance(model.weights());

这篇关于如何从MultilayerPerceptronClassifier获取分类概率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆