【发布时间】:2017-08-13 17:33:22
【问题描述】:
我的数据框中每天有 N 个特征,可以追溯到 20 天(时间序列):我有大约 400 个特征 x 100k 行。
我正在尝试识别最重要的特征,因此我通过这种方式训练了我的 XGBoost 模型:
model = xgb.XGBRegressor(learning_rate=0.01, n_estimators=1000, max_depth=20)
eval_set = [(X_test, y_test)]
model.fit(X_train, y_train, eval_metric="rmse", eval_set=eval_set, verbose=True, early_stopping_rounds=20)
然后:
def plot_fimportance(xgbmodel, df_x, top_n=30):
features = df_x.columns.values
mapFeat = dict(zip(["f"+str(i) for i in range(len(features))],features))
ts = pd.Series(xgbmodel.booster().get_fscore())
ts.index = ts.reset_index()['index'].map(mapFeat)
ts.order()[-top_n:].plot(kind="barh", x = 'Feature', figsize = (8, top_n-10), title=("feature importance"))
plot_fimportance(model, df.drop(['label']))
我听说参数 max_depth 应该这样计算:
max_depth = 特征数 / 3
我认为这可能适用于小型数据集,但如果我使用 max_depth=133 训练我的模型,我的电脑可能会爆炸,而且我可能也会过拟合。
我怎么能用这么多的特征计算 max_depth 的最佳值?
【问题讨论】:
标签: python machine-learning scikit-learn xgboost