apache-spark - 使用 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 一起使用时,是否有正确的方法来获取特征重要性
解决方案
我是这个领域的新手。我碰巧遇到了你正在经历的事情。您可能想尝试使用:model.nativeBooster.getScore("", "gain") or model.nativeBooster.getFeatureScore('')
。
我的“模型”属于“sparkxgb.xgboost.XGBoostClassificationModel”类型。
问候
推荐阅读
- python - 如何将 jpg 或 png 文件转换为 csv 文件?
- python - 如何指定具有重复值的字典列表?
- javascript - Mongoose find - 从查询中返回所有匹配的至少一个
- julia - Julia中函数调用的歧义
- f# - F# LiteDB [
] 被忽略? - javascript - 如何检查身份验证令牌是否已过期并强制注销?
- android - 如何将雅虎天气 API 中的日期解析为 Java 日期
- javascript - 尝试将 JSON POST 发送到 Discord Webhook 时,urlFetchApp.fetch() 似乎静默失败
- android - 如何将activity_main布局文件连接到非主要活动
- java - .split() 包含字符“++”的字符串