这似乎与:How to get the probability per instance in classifications models in spark.mllib最相关
我正在使用spark ml进行分类任务,构建一个MultilayerPerceptronClassifier.一旦我构建了一个模型,我可以得到一个给定输入向量的预测类,但是我不能得到每个输出类的概率.上面的清单表明NaiveBayesModel从Spark 1.5.0 (using a predictProbabilities method)开始支持此功能.我想获得MLPC的这个功能.有没有办法可以破解它来获取我的概率?它会包含在1.6.2中吗?
解决方法:
如果您看一下this line in the MLPC source code,您可以看到MLPC正在使用基础TopologyModel,它提供了我正在寻找的.predict方法. MLPC将得到的Vector解码为单个标签.
我能够使用训练有素的MLPC模型使用其权重创建一个新的TopologyModel:
MultilayerPerceptronClassifier trainer = new MultilayerPerceptronClassifier()...;
MultilayerPerceptronClassificationModel model = trainer.fit(trainingData);
TopologyModel topoModel = FeedForwardTopology.multiLayerPerceptron(model.layers(), true).getInstance(model.weights());
原文地址:https://codeday.me/bug/20190706/1396260.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。