xgboost基尼特征重要性-标准化数据与原始数据



我有一个XGBoost模型,如果我传入标准化数据与非标准化数据,我得到的基尼系数功能重要性是完全不同的。我认为xgboost不受标准化的影响。你能帮我理解吗?

from xgboost import XGBClassifier
import pandas as pd
import matplotlib.pyplot as plt

def train_model(x_train, y_train, x_test, y_test):
xg = XGBClassifier(n_estimators=350, subsample=1.0, scale_pos_weight=25, min_child_weight=8, max_depth=21,
learning_rate=0.1, gamma=0.2, colsample_bytree=0.5)
xg.fit(x_train, y_train)
return xg
def find_feat_imp(model, cols):
feat_importance = pd.Series(model.feature_importances_, index=cols)
sort_feat_imp = feat_importance.sort_values(ascending=False)
sort_feat_imp
sort_feat_imp[:20].plot(kind='bar')
plt.show()
x_train, y_train, x_test, y_test  = read_data()
xg = train_model(x_train, y_train, x_test, y_test)
find_feat_imp(xg,x_train.columns)

标准化数据输出为(https://i.stack.imgur.com/i6sW0.png),原始数据输出为(https://i.stack.imgur.com/If5u8.png)

重要的特征是完全不同的。你能帮我理解吗?

我希望特性的重要性是相同的,因为xgboost不受标准化数据的影响。

您没有设置随机种子,因此模型可能只是由于随机机会而不同。特别地,因为您设置了colsample_bytree<1,您得到了一个随机效应,其中每棵树中的列是可用的。因为第一个树通常是最具影响力的,如果一个特征碰巧被遗漏了,它的重要性得分就会受到影响。(不过请注意,xgboost支持几种重要特性类型;根据您使用的类型,此效果可能或多或少明显。

与许多其他基于树的模型一样,XGBoost不受特征缩放的影响,因为算法根据特征的值拆分数据,而不是使用特征的缩放。然而,XGBoost生成的特征重要性分数可能会受到特征缩放的影响,因为它们是基于特征对每次分割时杂质标准(例如基尼杂质)减少的贡献。将数据标准化可以改变特征的相对尺度,这反过来又可以改变由杂质减少准则确定的它们的相对重要性。因此,在比较特征重要性值时,建议使用相同的数据预处理方法。

最新更新