XGBoost 參數說明

XGBoost使用key-value字典的方式存儲參數:


params = {
    'booster': 'gbtree',
    'objective': 'multi:softmax',  # 多分類的問題
    'num_class': 10,       # 類別數,與 multisoftmax 並用
    'gamma': 0.1,      # 用於控制是否後剪枝的參數,越大越保守,一般0.1、0.2這樣子。
    'max_depth': 12,       # 構建樹的深度,越大越容易過擬合
    'lambda': 2,          # 控制模型複雜度的權重值的L2正則化項參數,參數越大,模型越不容易過擬合。
    'subsample': 0.7,           # 隨機採樣訓練樣本
    'colsample_bytree': 0.7,       # 生成樹時進行的列採樣
    'min_child_weight': 3,
    'silent': 1,                   # 設置成1則沒有運行信息輸出,最好是設置爲0.
    'eta': 0.007,                  # 如同學習率
    'seed': 1000,
    'nthread': 4,                  # cpu 線程數
}

在運行XGboost之前,必須設置三種類型成熟:general parameters,booster parameters和task parameters:

  • General parameters 
    該參數參數控制在提升(boosting)過程中使用哪種booster,常用的booster有樹模型(tree)和線性模型(linear model)。

  • Booster parameters 
    這取決於使用哪種booster。

  • Task parameters 
    控制學習的場景,例如在迴歸問題中會使用不同的參數控制排序。

————————————————————————

  • booster [default=gbtree]

    有兩中模型可以選擇gbtree和gblinear。gbtree使用基於樹的模型進行提升計算,gblinear使用線性模型進行提升計算。缺省值爲gbtree

  • silent [default=0]

    取0時表示打印出運行時信息,取1時表示以緘默方式運行,不打印運行時信息。缺省值爲0

  • nthread

    XGBoost運行時的線程數。缺省值是當前系統可以獲得的最大線程數

  • num_pbuffer

    預測緩衝區大小,通常設置爲訓練實例的數目。緩衝用於保存最後一步提升的預測結果,無需人爲設置。

  • num_feature

    Boosting過程中用到的特徵維數,設置爲特徵個數。XGBoost會自動設置,無需人爲設置。


##  Parameters for Tree Booster

  • eta [default=0.3] 
    爲了防止過擬合,更新過程中用到的收縮步長。在每次提升計算之後,算法會直接獲得新特徵的權重。 eta通過縮減特徵的權重使提升計算過程更加保守。缺省值爲0.3 
    取值範圍爲:[0,1]

  • gamma [default=0] 
    minimum loss reduction required to make a further partition on a leaf node of the tree. the larger, the more conservative the algorithm will be. 
    取值範圍爲:[0,∞]

  • max_depth [default=6] 
    數的最大深度。缺省值爲6 
    取值範圍爲:[1,∞]

  • min_child_weight [default=1] 
    孩子節點中最小的樣本權重和。如果一個葉子節點的樣本權重和小於min_child_weight則拆分過程結束。在現行迴歸模型中,這個參數是指建立每個模型所需要的最小樣本數。該成熟越大算法越conservative 
    取值範圍爲:[0,∞]

  • max_delta_step [default=0] 
    我們允許每個樹的權重被估計的值。如果它的值被設置爲0,意味着沒有約束;如果它被設置爲一個正值,它能夠使得更新的步驟更加保守。通常這個參數是沒有必要的,但是如果在邏輯迴歸中類極其不平衡這時候他有可能會起到幫助作用。把它範圍設置爲1-10之間也許能控制更新。 
    取值範圍爲:[0,∞]

  • subsample [default=1] 
    用於訓練模型的子樣本佔整個樣本集合的比例。如果設置爲0.5則意味着XGBoost將隨機的從整個樣本集合中隨機的抽取出50%的子樣本建立樹模型,這能夠防止過擬合。 
    取值範圍爲:(0,1]

  • colsample_bytree [default=1] 
    在建立樹時對特徵採樣的比例。缺省值爲1 
    取值範圍爲:(0,1]

##   Parameter for Linear Booster

  • lambda [default=0] 
    L2 正則的懲罰係數

  • alpha [default=0] 
    L1 正則的懲罰係數

  • lambda_bias 
    在偏置上的L2正則。缺省值爲0(在L1上沒有偏置項的正則,因爲L1時偏置不重要)



##  Task Parameters

  • objective [ default=reg:linear ] 
    定義學習任務及相應的學習目標,可選的目標函數如下:

    • “reg:linear” —— 線性迴歸。

    • “reg:logistic”—— 邏輯迴歸。

    • “binary:logistic”—— 二分類的邏輯迴歸問題,輸出爲概率。

    • “binary:logitraw”—— 二分類的邏輯迴歸問題,輸出的結果爲wTx。

    • “count:poisson”—— 計數問題的poisson迴歸,輸出結果爲poisson分佈。在poisson迴歸中,max_delta_step的缺省值爲0.7。(used to safeguard optimization)

    • “multi:softmax” –讓XGBoost採用softmax目標函數處理多分類問題,同時需要設置參數num_class(類別個數)

    • “multi:softprob” –和softmax一樣,但是輸出的是ndata * nclass的向量,可以將該向量reshape成ndata行nclass列的矩陣。沒行數據表示樣本所屬於每個類別的概率。

    • “rank:pairwise” –set XGBoost to do ranking task by minimizing the pairwise loss

  • base_score [ default=0.5 ]

    • 所有實例的初始化預測分數,全局偏置;

    • 爲了足夠的迭代次數,改變這個值將不會有太大的影響。

  • eval_metric [ default according to objective ]

    • “rmse”: root mean square error

    • “logloss”: negative log-likelihood

    • “error”: Binary classification error rate. It is calculated as #(wrong cases)/#(all cases). For the predictions, the evaluation will regard the instances with prediction value larger than 0.5 as positive instances, and the others as negative instances.

    • “merror”: Multiclass classification error rate. It is calculated as #(wrongcases)#(allcases).

    • “mlogloss”: Multiclass logloss

    • “auc”: Area under the curve for ranking evaluation.

    • “ndcg”:Normalized Discounted Cumulative Gain

    • “map”:Mean average precision

    • “ndcg@n”,”map@n”: n can be assigned as an integer to cut off the top positions in the lists for evaluation.

    • “ndcg-“,”map-“,”ndcg@n-“,”map@n-“: In XGBoost, NDCG and MAP will evaluate the score of a list without any positive samples as 1. By adding “-” in the evaluation metric XGBoost will evaluate these score as 0 to be consistent under some conditions. training repeatively

    • 校驗數據所需要的評價指標,不同的目標函數將會有缺省的評價指標(rmse for regression, and error for classification, mean average precision for ranking)-

    • 用戶可以添加多種評價指標,對於Python用戶要以list傳遞參數對給程序,而不是map參數list參數不會覆蓋’eval_metric’

    • 可供的選擇如下:

  • seed [ default=0 ]

    • 隨機數的種子。缺省值爲0


refer  : https://www.cnblogs.com/timxgb/p/8231130.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章