【问题标题】:Get feature importance with PySpark and XGboost使用 PySpark 和 XGboost 获取特征重要性
【发布时间】:2020-08-20 04:20:56
【问题描述】:

我已经使用 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-spark pyspark xgboost


    【解决方案1】:

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

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

    问候

    【讨论】:

    • 但是,结果是JavaObject类型。如何将java对象转换为python dict?
    • @volity 你知道如何将 java 对象转换为 python dict 吗?
    猜你喜欢
    • 1970-01-01
    • 2019-12-13
    • 2022-01-19
    • 2020-09-11
    • 2019-04-15
    • 2019-06-04
    • 2018-06-30
    • 2020-03-17
    • 2015-05-12
    相关资源
    最近更新 更多