我正在尝试提取我使用PySpark训练的随机森林对象的类概率.但是,我没有在文档中的任何地方看到它的示例,也不是它的方法RandomForestModel.
如何从RandomForestModelPySpark中的分类器中提取类概率?
以下是文档中提供的示例代码,它仅提供最终类(而不是概率):
from pyspark.mllib.tree import RandomForest
from pyspark.mllib.util import MLUtils
# Load and parse the data file into an RDD of LabeledPoint.
data = MLUtils.loadLibSVMFile(sc, 'data/mllib/sample_libsvm_data.txt')
# Split the data into training and test sets (30% held out for testing)
(trainingData, testData) = data.randomSplit([0.7, 0.3])
# Train a RandomForest model.
# Empty categoricalFeaturesInfo indicates all features are continuous.
# Note: Use larger numTrees in practice.
# Setting featureSubsetStrategy="auto" lets the algorithm choose.
model = RandomForest.trainClassifier(trainingData, …Run Code Online (Sandbox Code Playgroud) 我正在使用Spark 1.5.1和In pyspark,之后我使用以下模型拟合模型:
model = LogisticRegressionWithLBFGS.train(parsedData)
Run Code Online (Sandbox Code Playgroud)
我可以使用以下方式打印预测:
model.predict(p.features)
Run Code Online (Sandbox Code Playgroud)
是否有功能打印概率分数以及预测?
machine-learning logistic-regression apache-spark pyspark apache-spark-mllib