从管道中提取featureImportance

时间:2017-09-22 00:42:45

标签: scala apache-spark apache-spark-ml

扩展DecisionTreeRegressionModel的模型使用featureImportances方法。如果使用Pipelines构建模型,则会有Model[_]类型的对象。

对于那些支持该方法的模型,如何从这些管道中获取featureImportances

1 个答案:

答案 0 :(得分:0)

如果您知道决策树所在的管道的哪个阶段很容易。例如,如果决策树处于第三阶段,您可以执行以下操作:

val featureImportances = pipelineModel
  .stages(2)  // The position in the pipeline of the stage you want
  .asInstanceOf[DecisionTreeRegressionModel]
  .featureImportances