sparkxgboost4j:如何获得特性重要性?

kwvwclae  于 2021-05-27  发布在  Spark
关注(0)|答案(1)|浏览(1436)

我在spark上运行xgboost并遇到 AttributeError: 'XGBoostClassifier' object has no attribute 'booster' ```
def train_model(trainDF):
xgboost = XGBoostClassifier(
featuresCol="features",
labelCol="label",
predictionCol="prediction",
objective='multi:softprob',
numClass=10,
missing=0.0
)
pipeline = Pipeline(stages=[xgboost])
model = pipeline.fit(trainDF)
featureScoreMap = xgb_model.booster.getFeatureScore()

如何获得xgboost4j的特性重要性?
uz75evzq

uz75evzq1#

试试这个-从pipelinemodel获得重要的特性,第一阶段是xgboost模型

在斯卡拉

val xgboostModel = model.stages.apply(0).asInstanceOf[XGBoostClassificationModel]

xgboostModel.nativeBooster.getFeatureScore()

在python中(来自注解)

model.stages[0].nativeBooster.getScore("", "gain")

相关问题