xgboost多線程預(yù)測的不安全問題
xgboost的predict_proba
官網(wǎng)上說了,predict_proba是一個多線程不安全的方法,主要是因為預(yù)測的一個C++代碼內(nèi)部調(diào)用的時候有一個PredLoopSpecalize,里面對openmp的thread_temp變量作為類成員變量,在多線程會被當(dāng)成公共變量修改。說白了就是有預(yù)測的內(nèi)部變量是公共變量。
xgboost特征重要性
如何獲取特征重要性:booster中有三種獲取方式:
Importance type can be defined as:
'weight' - the number of times a feature is used to split the data across all trees.
'gain' - the average gain of the feature when it is used in trees
'cover' - the average coverage of the feature when it is used in trees
默認是用weight來顯示,但是不一定準確
cover: the sum of second order gradient of training data classified to the leaf, if it is square loss, this simply corresponds to the number of instances in that branch. Deeper in the tree a node is, lower this metric will be
XGBoost函數(shù)筆記
XGBoost核心代碼基于C++開發(fā),訓(xùn)練和預(yù)測都是C++代碼,外部由Python封裝。
最常用的兩個類是:
- xgboost.XGBClassifier分類器
- xgboost.XGBRegressor回歸器
兩個類都繼承了XGBModel,XGBModel實現(xiàn)了sklearn的接口
其中分類和回歸都是基于booster來完成的,內(nèi)部有個Booster類,非常重要,每個booset都是一個單獨的模型,內(nèi)部有很多函數(shù),比如get_score,get_dump等函數(shù),都非常有用。booset里面很多函數(shù)也是和C代碼結(jié)合的部分。
booster類別初探
booster有三種選擇: gbtree, gblinear or dart.
- gbtree 梯度提升樹,常用,默認
- gblinear就是一個線性分類/回歸器
- dart 帶dropout的
gblinear
利用gblinear訓(xùn)練出的結(jié)果就是一個線性分類器
并行化
樹內(nèi)的部可以做并行,在一次分裂之后,子樹的分裂可以通過