How to get classification probabilities from MultilayerPerceptronClassifier?

This, apparently, is most of all related to: How to get the probability for an instance in classification models in spark.mllib

I am doing a classification task with spark ml by creating a MultilayerPerceptronClassifier. Once I build the model, I can get the predicted class based on the input vector, but I cannot get the probability for each output class. The above list indicates that NaiveBayesModel supports this functionality with Spark 1.5.0 (using the predvProbabilities method) . I would like to get this functionality for MLPC. Is there a way I can crack it to get my probabilities? Will it be included in 1.6.2?

+3
java scala apache-spark apache-spark-ml
source share
2 answers

If you look at this line in the MLPC source code , you will see that MLPC works with the base TopologyModel which provides the .predict method I'm looking for. MLPC decodes the resulting Vector into a single label.

I can use the prepared 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()); 
0
source share

I think the short answer is No.

A multilayer cluster analyzer is not probabilistic. When weights (and any offsets) are set after training, the classification for a given input will always be the same.

What you really ask, I think, is "if I were to adjust the weights with certain random violations of a given value, how likely is the classification the same as without tricks?"

You can do the ad hoc probability calculation by retraining the perceptron (with different, randomly selected initial conditions) and get some idea of ​​the probability of different classifications.

But I do not think that this is really part of the expected behavior of the MLPC.

-one
source share

All Articles