【发布时间】:2020-03-17 22:47:05
【问题描述】:
在 XGBOOST 特征重要性中使用两种不同的方法,给了我两个不同的最重要的特征,应该相信哪一个?
什么时候应该使用什么方法?我很困惑。
设置
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
import xgboost as xgb
df = sns.load_dataset('mpg')
df = df.drop(['name','origin'],axis=1)
X = df.iloc[:,1:]
y = df.iloc[:,0]
Numpy 数组
# fit the model
model_xgb_numpy = xgb.XGBRegressor(n_jobs=-1,objective='reg:squarederror')
model_xgb_numpy.fit(X.to_numpy(), y.to_numpy())
plt.bar(range(len(model_xgb_numpy.feature_importances_)), model_xgb_numpy.feature_importances_)
熊猫数据框
# fit the model
model_xgb_pandas = xgb.XGBRegressor(n_jobs=-1,objective='reg:squarederror')
model_xgb_pandas.fit(X, y)
axsub = xgb.plot_importance(model_xgb_pandas)
问题
Numpy 方法显示第 0 个特征圆柱是最重要的。 Pandas 方法表明车型年份是最重要的。哪个是正确的最重要的功能?
参考文献
【问题讨论】: