1.xgboost对特征重要性排序的原理
xgboost根据结构分数的增益情况计算出来选择哪个特征作为分割点,而某个特征的重要性就是它在所有树中出现的次数之和。也就是说一个属性越多的被用来在模型中构建决策树,它的重要性就相对越高
2 xgboost特征重要性排序的方法
-
xgboost可以通过get_score获取特征重要性
for importance_type in (‘weight’, ‘gain’, ‘cover’, ‘total_gain’, ‘total_cover’):
print(’%s: ’ % importance_type, bst.get_score(importance_type=importance_type))
weight - 该特征在所有树中被用作分割样本的特征的次数。
gain - 在所有树中的平均增益。
cover - 在树中使用该特征时的平均覆盖范围。(还不是特别明白) -
利用plot_importance画出各个特征的重要性排序
-
可以通过测试多个阈值,借助衡量分类器优劣的指标,来从特征重要性中选择特征。
下面利用kaggle的heartdisease数据实证分析
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split,StratifiedKFold,train_test_split,GridSearchCV
from sklearn.metrics import accuracy_score, confusion_matrix, mean_squared_error,roc_auc_score
from xgboost import plot_importance
from matplotl

本文深入探讨了XGBoost中特征重要性的计算原理及排序方法,包括weight、gain和cover等不同指标,并通过Kaggle的心脏病数据集进行实证分析,展示了如何使用这些指标选择最优特征。
最低0.47元/天 解锁文章
4660





