首页 > 解决方案 > 使用 PySpark 和 XGboost 获取特征重要性

问题描述

我已经使用 XGboost 和 PySpark 训练了一个模型

params = { 
    'eta': 0.1,
    'gamma': 0.1,
    'missing': 0.0,
    'treeMethod': 'gpu_hist',
    'maxDepth': 10, 
    'maxLeaves': 256,
    'growPolicy': 'depthwise',
    'objective': 'binary:logistic',
    'minChildWeight': 30.0,
    'lambda_': 1.0,
    'scalePosWeight': 2.0,
    'subsample': 1.0,
    'nthread': 1,
    'numRound': 100,
    'numWorkers': 1,
}

classifier = XGBoostClassifier(**params).setLabelCol(label).setFeaturesCols(features)


model = classifier.fit(train_data)

当我尝试使用

model.nativeBooster.getFeatureScore()

它返回以下错误:

Py4JError: An error occurred while calling o2167.getFeatureScore. Trace:
py4j.Py4JException: Method getFeatureScore([]) does not exist

将 XGboost 与 PySpark 一起使用时,是否有正确的方法来获取特征重要性

标签: apache-sparkpysparkxgboost

解决方案


我是这个领域的新手。我碰巧遇到了你正在经历的事情。您可能想尝试使用:model.nativeBooster.getScore("", "gain") or model.nativeBooster.getFeatureScore('')

我的“模型”属于“sparkxgb.xgboost.XGBoostClassificationModel”类型。

问候


推荐阅读