
204
|
第七章:整體學習與隨機森林
你也可以讓梯度增強使用其他的代價函數
。
這是用
loss
超參數來控制的
(
詳情見
Scikit-Learn
的文件
)。
值得一提的是
,
熱門的
Python
程式庫
XGBoost(https://github.com/dmlc/xgboost)
提供了優
化的梯度增強實作
,XGBoost
是
Extreme Gradient Boosting
的縮寫
。
這個程式庫最初是由
Distributed(Deep)Machine Learning Community(DMLC)
的
Tianqi Chen
開發的
,
期望
有極快的速度
、
極好的擴展性和可移植性
。
事實上
,XGBoost
往往是各種
ML
競賽獲勝作
品的重要元素
。XGBoost
的
API
很像
Scikit-Learn
的
:
import xgboost
xgb_reg = xgboost.XGBRegressor()
xgb_reg.fit(X_train, y_train)
y_pred = xgb_reg.predict(X_val)
XGBoost
也提供了一些很棒的功能
,
例如自動處理提前停止
:
xgb_reg.fit(X_train, y_train,
eval_set=[(X_val, y_val)], early_stopping_rounds=2)
y_pred = xgb_reg.predict(X_val)
你一定要好好研究它
!
stacking
本章探討的最後一種整體方法稱為
stacking(stacked generalization
的簡稱 ...