我正在尝试使用PySpark提取已训练的随机森林对象的特征重要性。然而,在文档中我没有看到任何实现此操作的例子,而且RandomForestModel
也没有相应的方法。
我该如何从 PySpark 中的RandomForestModel
回归器或分类器中提取特征重要性呢?下面是文档中提供的示例代码,但其中并没有提到特征重要性。
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, numClasses=2, categoricalFeaturesInfo={},
numTrees=3, featureSubsetStrategy="auto",
impurity='gini', maxDepth=4, maxBins=32)
我找不到model.__featureImportances_
属性 -- 我应该在哪里查找?