【发布时间】:2021-10-23 06:54:08
【问题描述】:
我想问是否有办法提取最重要特征的名称并将它们保存在 pandas 数据框中。我知道如何绘制它们以及如何获取它们,但我正在寻找一种方法来将最重要的特征保存在数据框中。
from xgboost import XGBClassifier
from xgboost import plot_importance
# fit model to training data
xgb_model = XGBClassifier(random_state=0)
xgb_model.fit(X, y)
print("Feature Importances : ", xgb_model.feature_importances_)
# plot feature importance
fig, ax = plt.subplots(figsize=(15, 10))
plot_importance(xgb_model, max_num_features=35, height=1, ax=ax)
plt.show()
【问题讨论】:
标签: python pandas dataframe xgboost