java - 如何从 MultilayerPerceptronClassifier 获取分类概率?

标签 java scala apache-spark apache-spark-ml

这似乎最相关:How to get the probability per instance in classifications models in spark.mllib

我正在使用 spark ml 执行分类任务,构建一个 MultilayerPerceptronClassifier。建立模型后,我可以获得给定输入 vector 的预测类别,但我无法获得每个输出类别的概率。上面的 list 表明 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());

关于java - 如何从 MultilayerPerceptronClassifier 获取分类概率?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35962952/

相关文章:

java - 开源 Java 报告框架

java - 如何为 Spring Boot 应用程序配置嵌入式 Tomcat 虚拟主机?

java - 无法在 stackdriver 中看到痕迹

java - Spark SQL RowFactory 返回空行

java - Apache Camel - 返回 200 状态代码并发送到队列

scala - 避免在基本特征中初始化覆盖的 `val`?

scala - 通过调用 toSet 丢失参数类型错误

scala - 术语 "reason about"在计算机科学中意味着什么?

sql - 如何从 VBA 连接到 Apache spark/hadoop

apache-spark - 如何为每行使用带有可变分隔符的拆分函数?