use*_*486 1 python machine-learning xgboost
我想将 XGboost 模型及其特征图转储到文本文件。这可以这样做;
\n\n# https://xgboost.readthedocs.io/en/latest/python/python_intro.html\nimport xgboost as xgb\nbst = xgb.train(param, dtrain, num_round, evallist)\n# dump model with feature map\nbst.dump_model('dump.raw.txt', 'featmap.txt')\n
Run Code Online (Sandbox Code Playgroud)\n\n不过,我正在使用 XGBClassifier。该方法dump_model
在 XGBClassifier 中不可用。
from xgboost import XGBClassifier\nxgboost_model = XGBClassifier()\nxgboost_model.fit(x_train, y_train)\n# line below can't work because dump_model is not available in XGBClassifier\nxgboost_model.dump_model(\xe2\x80\x98dump.raw.txt\xe2\x80\x99, 'featmap.txt\xe2\x80\x99) \n
Run Code Online (Sandbox Code Playgroud)\n\n如何使用 XGBClassifier 转储具有特征图的 XGBoost 模型?
\n\n我正在使用 python 3.7
\n我会回答我自己的问题。
从https://xgboost.readthedocs.io/en/latest/python/python_api.html,get_booster()
首先使用该函数获取该模型的底层 xgboost Booster。助推器具有dump_model
可用的功能。
bst = xgboost_model.get_booster()
bst.dump_model('dump.raw.txt', 'featmap.txt')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5726 次 |
最近记录: |