【问题标题】:how to use a larger 'max_depth' in xgboost如何在 xgboost 中使用更大的“max_depth”
【发布时间】:2022-06-28 00:39:07
【问题描述】:

我正在使用 xgboost 来拟合具有 2 个特征的数据。我已将“max_depth”设置为 30,但我得到了一棵深度为 11 的树。与 BP-net 相比,深度为 11 的树与数据不匹配。

    df_new = pd.DataFrame()
    df_new['ua'] = df['ua_norm']
    df_new['va'] = df['va_norm']
    df_new['pow'] = df['pow_unit_cap_norm']

    param_grid = {"n_estimators": [1],
                  'max_depth': [30],
                  'colsample_bytree': [1.0],
                  "alpha": [10]
                  }
    grid_search = GridSearchCV(
        xgb.XGBRegressor(),
        param_grid,
        cv=3,
        n_jobs=3,
        verbose=3,
        scoring='neg_mean_squared_error',
        return_train_score=True
    )


    grid_search.fit(np.array(df_new[['ua', 'va']]), np.array(df_new['pow']))
    model = grid_search.best_estimator_
    model.get_booster().feature_names = ['ua', 'va']
    tree_df = model.get_booster().trees_to_dataframe()
    tree_df.to_csv('tree.csv', index=False)
    scr = xgb.to_graphviz(model, num_trees=0)
    # src.format = "jpg"
    scr.view("./tree")

enter image description here

【问题讨论】:

    标签: parameters xgboost


    【解决方案1】:

    为什么你对 max_depth 和 alpha 使用这么大的值?

    最大树深度默认为三 (3),很少需要高于五 (5)(Tseng,2018 年)...对于树,最好设置一个较高的 L2 (lambda) 值和 L1 (alpha) 为零 (Chris, 2016) https://towardsdatascience.com/mastering-xgboost-2eb6bce6bc76

    顺便说一下,alpha 是一个正则化参数,这么高的值会降低树的深度。

    【讨论】:

      猜你喜欢
      • 2019-07-22
      • 2023-02-24
      • 2018-11-09
      • 2018-05-30
      • 2018-01-21
      • 2020-02-18
      • 1970-01-01
      • 2019-09-19
      • 2019-08-21
      相关资源
      最近更新 更多