日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

xgboost使用调参

發布時間:2024/4/17 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 xgboost使用调参 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

?

歡迎關注博主主頁,學習python視頻資源

https://blog.csdn.net/q383700092/article/details/53763328

調參后結果非常理想

from sklearn.model_selection import GridSearchCV from sklearn.datasets import load_breast_cancer from xgboost import XGBClassifier from sklearn.model_selection import train_test_split from sklearn import metricscancer=load_breast_cancer() X, y = cancer.data,cancer.targettrain_x, test_x, train_y, test_y=train_test_split(X,y,test_size=0.3,random_state=0) parameters= [{'learning_rate':[0.01,0.1,0.3],'n_estimators':[1000,1200,1500,2000,2500],'max_depth':range(1,10,1),'gamma':[0.01,0.1,0.3,0.5],'eta': [0.025,0.1,0.2,0.3]}]clf = GridSearchCV(XGBClassifier(min_child_weight=1,subsample=0.6,colsample_bytree=0.6,objective= 'binary:logistic', #邏輯回歸損失函數scale_pos_weight=1,reg_alpha=0,reg_lambda=1,seed=27), param_grid=parameters,scoring='roc_auc') clf.fit(train_x,train_y)y_pred=clf.predict(test_x)print("accuracy on the training subset:{:.3f}".format(clf.score(train_x,train_y))) print("accuracy on the test subset:{:.3f}".format(clf.score(test_x,test_y)))print(clf.best_params_) y_pre= clf.predict(test_x) y_pro= clf.predict_proba(test_x)[:,1] print ("AUC Score : %f" % metrics.roc_auc_score(test_y, y_pro)) print("Accuracy : %.4g" % metrics.accuracy_score(test_y, y_pre)) ''' accuracy on the training subset:1.000 accuracy on the test subset:0.998 {'gamma': 0.5, 'learning_rate': 0.01, 'max_depth': 2, 'n_estimators': 1000} AUC Score : 0.998089 Accuracy : 0.9708 '''best_xgb=XGBClassifier(min_child_weight=1,subsample=0.6,colsample_bytree=0.6,objective= 'binary:logistic', #邏輯回歸損失函數scale_pos_weight=1,reg_alpha=0,reg_lambda=1,seed=27,gamma=0.5,learning_rate=0.01,max_depth=2,n_estimators=1000)best_xgb.fit(train_x,train_y)print("accuracy on the training subset:{:.3f}".format(best_xgb.score(train_x,train_y))) print("accuracy on the test subset:{:.3f}".format(best_xgb.score(test_x,test_y)))''' accuracy on the training subset:0.995 accuracy on the test subset:0.979 '''

  

?

?

?

?

?

github:https://github.com/dmlc/xgboost?
論文參考:http://www.kaggle.com/blobs/download/forum-message-attachment-files/4087/xgboost-paper.pdf

基本思路及優點

http://blog.csdn.net/q383700092/article/details/60954996?
參考http://dataunion.org/15787.html?
http://blog.csdn.net/china1000/article/details/51106856?
在有監督學習中,我們通常會構造一個目標函數和一個預測函數,使用訓練樣本對目標函數最小化學習到相關的參數,然后用預測函數和訓練樣本得到的參數來對未知的樣本進行分類的標注或者數值的預測。?
1. Boosting Tree構造樹來擬合殘差,而Xgboost引入了二階導來進行求解,并且引入了節點的數目、參數的L2正則來評估模型的復雜度,構造Xgboost的預測函數與目標函數。?
2. 在分裂點選擇的時候也以目標函數最小化為目標。?
優點:?
1. 顯示的把樹模型復雜度作為正則項加到優化目標中。?
2. 公式推導中用到了二階導數,用了二階泰勒展開。(GBDT用牛頓法貌似也是二階信息)?
3. 實現了分裂點尋找近似算法。?
4. 利用了特征的稀疏性。?
5. 數據事先排序并且以block形式存儲,有利于并行計算。?
6. 基于分布式通信框架rabit,可以運行在MPI和yarn上。(最新已經不基于rabit了)?
7. 實現做了面向體系結構的優化,針對cache和內存做了性能優化。

原理推導及與GBDT區別

http://blog.csdn.net/q383700092/article/details/60954996?
參考http://dataunion.org/15787.html?
https://www.zhihu.com/question/41354392

參數說明

參考http://blog.csdn.net/han_xiaoyang/article/details/52665396?
參數?
booster:默認 gbtree效果好 (linear booster很少用到)?
gbtree:基于樹的模型?
gbliner:線性模型?
silent[默認0]?
nthread[默認值為最大可能的線程數]?
eta[默認0.3] 學習率 典型值為0.01-0.2?
min_child_weight[默認 1 ] 決定最小葉子節點樣本權重和 值較大,避免過擬合 值過高,會導致欠擬合?
max_depth[默認6]?
gamma[默認0] 指定了節點分裂所需的最小損失函數下降值。 這個參數的值越大,算法越保守?
subsample[默認1] 對于每棵樹,隨機采樣的比例 減小,算法保守,避免過擬合。值設置得過小,它會導致欠擬合 典型值:0.5-1?
colsample_bytree[默認1] 每棵隨機采樣的列數的占比?
colsample_bylevel[默認1] 樹的每一級的每一次分裂,對列數的采樣的占比?
lambda[默認1] 權重的L2正則化項?
alpha[默認1] 權重的L1正則化項?
scale_pos_weight[默認1] 在各類別樣本十分不平衡時,參數設定為一個正值,可以使算法更快收斂?
objective[默認reg:linear] 最小化的損失函數?
binary:logistic 二分類的邏輯回歸,返回預測的概率(不是類別)。 multi:softmax 使用softmax的多分類器,返回預測的類別(不是概率)。?
在這種情況下,你還需要多設一個參數:num_class(類別數目)。 multi:softprob 和multi:softmax參數一樣,但是返回的是每個數據屬于各個類別的概率。?
eval_metric[默認值取決于objective參數的取值]?
對于回歸問題,默認值是rmse,對于分類問題,默認值是error。 典型值有:?
rmse 均方根誤差 mae 平均絕對誤差 logloss 負對數似然函數值?
error 二分類錯誤率 merror 多分類錯誤率 mlogloss 多分類logloss損失函數 auc 曲線下面積?
seed(默認0) 隨機數的種子 設置它可以復現隨機數據的結果

sklearn包,XGBClassifier會改變的函數名?
eta ->learning_rate?
lambda->reg_lambda?
alpha->reg_alpha

常用調整參數:

參考?
https://www.analyticsvidhya.com/blog/2016/03/complete-guide-parameter-tuning-xgboost-with-codes-python/

第一步:確定學習速率和tree_based 參數調優的估計器數目

樹的最大深度一般3-10?
max_depth = 5?
節點分裂所需的最小損失函數下降值0.1到0.2?
gamma = 0?
采樣?
subsample= 0.8,?
colsample_bytree = 0.8?
比較小的值,適用極不平衡的分類問題?
min_child_weight = 1?
類別十分不平衡?
scale_pos_weight = 1

from xgboost import XGBClassifier xgb1 = XGBClassifier(learning_rate =0.1,n_estimators=1000,max_depth=5, min_child_weight=1, gamma=0, subsample=0.8, colsample_bytree=0.8, objective= 'binary:logistic', nthread=4, scale_pos_weight=1, seed=27)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

第二步: max_depth 和 min_weight 參數調優

grid_search參考?
http://scikit-learn.org/stable/modules/generated/sklearn.grid_search.GridSearchCV.html?
http://blog.csdn.net/abcjennifer/article/details/23884761?
網格搜索scoring=’roc_auc’只支持二分類,多分類需要修改scoring(默認支持多分類)

param_test1 = {'max_depth':range(3,10,2),'min_child_weight':range(1,6,2) } #param_test2 = {'max_depth':[4,5,6],'min_child_weight':[4,5,6] } from sklearn import svm, grid_search, datasets from sklearn import grid_search gsearch1 = grid_search.GridSearchCV( estimator = XGBClassifier( learning_rate =0.1, n_estimators=140, max_depth=5, min_child_weight=1, gamma=0, subsample=0.8, colsample_bytree=0.8, objective= 'binary:logistic', nthread=4, scale_pos_weight=1, seed=27), param_grid = param_test1, scoring='roc_auc', n_jobs=4, iid=False, cv=5) gsearch1.fit(train[predictors],train[target]) gsearch1.grid_scores_, gsearch1.best_params_,gsearch1.best_score_ #網格搜索scoring='roc_auc'只支持二分類,多分類需要修改scoring(默認支持多分類)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

第三步:gamma參數調優

param_test3 = {'gamma':[i/10.0 for i in range(0,5)] } gsearch3 = GridSearchCV( estimator = XGBClassifier( learning_rate =0.1, n_estimators=140, max_depth=4, min_child_weight=6, gamma=0, subsample=0.8, colsample_bytree=0.8, objective= 'binary:logistic', nthread=4, scale_pos_weight=1, seed=27), param_grid = param_test3, scoring='roc_auc', n_jobs=4, iid=False, cv=5) gsearch3.fit(train[predictors],train[target]) gsearch3.grid_scores_, gsearch3.best_params_, gsearch3.best_score_
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

第四步:調整subsample 和 colsample_bytree 參數

#取0.6,0.7,0.8,0.9作為起始值 param_test4 = {'subsample':[i/10.0 for i in range(6,10)],'colsample_bytree':[i/10.0 for i in range(6,10)] }gsearch4 = GridSearchCV( estimator = XGBClassifier( learning_rate =0.1, n_estimators=177, max_depth=3, min_child_weight=4, gamma=0.1, subsample=0.8, colsample_bytree=0.8, objective= 'binary:logistic', nthread=4, scale_pos_weight=1, seed=27), param_grid = param_test4, scoring='roc_auc', n_jobs=4, iid=False, cv=5) gsearch4.fit(train[predictors],train[target]) gsearch4.grid_scores_, gsearch4.best_params_, gsearch4.best_score_
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

第五步:正則化參數調優

param_test6 = {'reg_alpha':[1e-5, 1e-2, 0.1, 1, 100] } gsearch6 = GridSearchCV( estimator = XGBClassifier( learning_rate =0.1, n_estimators=177, max_depth=4, min_child_weight=6, gamma=0.1, subsample=0.8, colsample_bytree=0.8, objective= 'binary:logistic', nthread=4, scale_pos_weight=1, seed=27), param_grid = param_test6, scoring='roc_auc', n_jobs=4, iid=False, cv=5) gsearch6.fit(train[predictors],train[target]) gsearch6.grid_scores_, gsearch6.best_params_, gsearch6.best_score_
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

第六步:降低學習速率

xgb4 = XGBClassifier(learning_rate =0.01,n_estimators=5000,max_depth=4,min_child_weight=6,gamma=0, subsample=0.8, colsample_bytree=0.8, reg_alpha=0.005, objective= 'binary:logistic', nthread=4, scale_pos_weight=1, seed=27) modelfit(xgb4, train, predictors)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

python示例

import xgboost as xgb import pandas as pd #獲取數據 from sklearn import cross_validation from sklearn.datasets import load_iris iris = load_iris() #切分數據集 X_train, X_test, y_train, y_test = cross_validation.train_test_split(iris.data, iris.target, test_size=0.33, random_state=42) #設置參數 m_class = xgb.XGBClassifier( learning_rate =0.1, n_estimators=1000, max_depth=5, gamma=0, subsample=0.8, colsample_bytree=0.8, objective= 'binary:logistic', nthread=4, seed=27) #訓練 m_class.fit(X_train, y_train) test_21 = m_class.predict(X_test) print "Accuracy : %.2f" % metrics.accuracy_score(y_test, test_21) #預測概率 #test_2 = m_class.predict_proba(X_test) #查看AUC評價標準 from sklearn import metrics print "Accuracy : %.2f" % metrics.accuracy_score(y_test, test_21) ##必須二分類才能計算 ##print "AUC Score (Train): %f" % metrics.roc_auc_score(y_test, test_2) #查看重要程度 feat_imp = pd.Series(m_class.booster().get_fscore()).sort_values(ascending=False) feat_imp.plot(kind='bar', title='Feature Importances') import matplotlib.pyplot as plt plt.show() #回歸 #m_regress = xgb.XGBRegressor(n_estimators=1000,seed=0) #m_regress.fit(X_train, y_train) #test_1 = m_regress.predict(X_test)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39

整理

xgb原始

from sklearn.model_selection import train_test_split from sklearn import metrics from sklearn.datasets import make_hastie_10_2 import xgboost as xgb #記錄程序運行時間 import time start_time = time.time() X, y = make_hastie_10_2(random_state=0) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=0)##test_size測試集合所占比例 #xgb矩陣賦值 xgb_train = xgb.DMatrix(X_train, label=y_train) xgb_test = xgb.DMatrix(X_test,label=y_test) ##參數 params={ 'booster':'gbtree', 'silent':1 ,#設置成1則沒有運行信息輸出,最好是設置為0. #'nthread':7,# cpu 線程數 默認最大 'eta': 0.007, # 如同學習率 'min_child_weight':3, # 這個參數默認是 1,是每個葉子里面 h 的和至少是多少,對正負樣本不均衡時的 0-1 分類而言 #,假設 h 在 0.01 附近,min_child_weight 為 1 意味著葉子節點中最少需要包含 100 個樣本。 #這個參數非常影響結果,控制葉子節點中二階導的和的最小值,該參數值越小,越容易 overfitting。 'max_depth':6, # 構建樹的深度,越大越容易過擬合 'gamma':0.1, # 樹的葉子節點上作進一步分區所需的最小損失減少,越大越保守,一般0.1、0.2這樣子。 'subsample':0.7, # 隨機采樣訓練樣本 'colsample_bytree':0.7, # 生成樹時進行的列采樣 'lambda':2, # 控制模型復雜度的權重值的L2正則化項參數,參數越大,模型越不容易過擬合。 #'alpha':0, # L1 正則項參數 #'scale_pos_weight':1, #如果取值大于0的話,在類別樣本不平衡的情況下有助于快速收斂。 #'objective': 'multi:softmax', #多分類的問題 #'num_class':10, # 類別數,多分類與 multisoftmax 并用 'seed':1000, #隨機種子 #'eval_metric': 'auc' } plst = list(params.items()) num_rounds = 100 # 迭代次數 watchlist = [(xgb_train, 'train'),(xgb_test, 'val')] #訓練模型并保存 # early_stopping_rounds 當設置的迭代次數較大時,early_stopping_rounds 可在一定的迭代次數內準確率沒有提升就停止訓練 model = xgb.train(plst, xgb_train, num_rounds, watchlist,early_stopping_rounds=100,pred_margin=1) #model.save_model('./model/xgb.model') # 用于存儲訓練出的模型 print "best best_ntree_limit",model.best_ntree_limit y_pred = model.predict(xgb_test,ntree_limit=model.best_ntree_limit) print ('error=%f' % ( sum(1 for i in range(len(y_pred)) if int(y_pred[i]>0.5)!=y_test[i]) /float(len(y_pred)))) #輸出運行時長 cost_time = time.time()-start_time print "xgboost success!",'\n',"cost time:",cost_time,"(s)......"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

xgb使用sklearn接口(推薦)

官方?
會改變的函數名是:?
eta -> learning_rate?
lambda -> reg_lambda?
alpha -> reg_alpha

from sklearn.model_selection import train_test_split from sklearn import metrics from sklearn.datasets import make_hastie_10_2 from xgboost.sklearn import XGBClassifier X, y = make_hastie_10_2(random_state=0) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=0)##test_size測試集合所占比例 clf = XGBClassifier( silent=0 ,#設置成1則沒有運行信息輸出,最好是設置為0.是否在運行升級時打印消息。 #nthread=4,# cpu 線程數 默認最大 learning_rate= 0.3, # 如同學習率 min_child_weight=1, # 這個參數默認是 1,是每個葉子里面 h 的和至少是多少,對正負樣本不均衡時的 0-1 分類而言 #,假設 h 在 0.01 附近,min_child_weight 為 1 意味著葉子節點中最少需要包含 100 個樣本。 #這個參數非常影響結果,控制葉子節點中二階導的和的最小值,該參數值越小,越容易 overfitting。 max_depth=6, # 構建樹的深度,越大越容易過擬合 gamma=0, # 樹的葉子節點上作進一步分區所需的最小損失減少,越大越保守,一般0.1、0.2這樣子。 subsample=1, # 隨機采樣訓練樣本 訓練實例的子采樣比 max_delta_step=0,#最大增量步長,我們允許每個樹的權重估計。 colsample_bytree=1, # 生成樹時進行的列采樣 reg_lambda=1, # 控制模型復雜度的權重值的L2正則化項參數,參數越大,模型越不容易過擬合。 #reg_alpha=0, # L1 正則項參數 #scale_pos_weight=1, #如果取值大于0的話,在類別樣本不平衡的情況下有助于快速收斂。平衡正負權重 #objective= 'multi:softmax', #多分類的問題 指定學習任務和相應的學習目標 #num_class=10, # 類別數,多分類與 multisoftmax 并用 n_estimators=100, #樹的個數 seed=1000 #隨機種子 #eval_metric= 'auc' ) clf.fit(X_train,y_train,eval_metric='auc') #設置驗證集合 verbose=False不打印過程 clf.fit(X_train, y_train,eval_set=[(X_train, y_train), (X_val, y_val)],eval_metric='auc',verbose=False) #獲取驗證集合結果 evals_result = clf.evals_result() y_true, y_pred = y_test, clf.predict(X_test) print"Accuracy : %.4g" % metrics.accuracy_score(y_true, y_pred) #回歸 #m_regress = xgb.XGBRegressor(n_estimators=1000,seed=0)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

網格搜索

可以先固定一個參數 最優化后繼續調整?
第一步:確定學習速率和tree_based 給個常見初始值 根據是否類別不平衡調節?
max_depth,min_child_weight,gamma,subsample,scale_pos_weight?
max_depth=3 起始值在4-6之間都是不錯的選擇。?
min_child_weight比較小的值解決極不平衡的分類問題eg:1?
subsample, colsample_bytree = 0.8: 這個是最常見的初始值了?
scale_pos_weight = 1: 這個值是因為類別十分不平衡。?
第二步: max_depth 和 min_weight 對最終結果有很大的影響?
‘max_depth’:range(3,10,2),?
‘min_child_weight’:range(1,6,2)?
先大范圍地粗調參數,然后再小范圍地微調。?
第三步:gamma參數調優?
‘gamma’:[i/10.0 for i in range(0,5)]?
第四步:調整subsample 和 colsample_bytree 參數?
‘subsample’:[i/100.0 for i in range(75,90,5)],?
‘colsample_bytree’:[i/100.0 for i in range(75,90,5)]?
第五步:正則化參數調優?
‘reg_alpha’:[1e-5, 1e-2, 0.1, 1, 100]?
‘reg_lambda’?
第六步:降低學習速率?
learning_rate =0.01,

from sklearn.model_selection import GridSearchCV tuned_parameters= [{'n_estimators':[100,200,500], 'max_depth':[3,5,7], ##range(3,10,2) 'learning_rate':[0.5, 1.0], 'subsample':[0.75,0.8,0.85,0.9] }] tuned_parameters= [{'n_estimators':[100,200,500,1000] }] clf = GridSearchCV(XGBClassifier(silent=0,nthread=4,learning_rate= 0.5,min_child_weight=1, max_depth=3,gamma=0,subsample=1,colsample_bytree=1,reg_lambda=1,seed=1000), param_grid=tuned_parameters,scoring='roc_auc',n_jobs=4,iid=False,cv=5) clf.fit(X_train, y_train) ##clf.grid_scores_, clf.best_params_, clf.best_score_ print(clf.best_params_) y_true, y_pred = y_test, clf.predict(X_test) print"Accuracy : %.4g" % metrics.accuracy_score(y_true, y_pred) y_proba=clf.predict_proba(X_test)[:,1] print "AUC Score (Train): %f" % metrics.roc_auc_score(y_true, y_proba)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
from sklearn.model_selection import GridSearchCV parameters= [{'learning_rate':[0.01,0.1,0.3],'n_estimators':[1000,1200,1500,2000,2500]}] clf = GridSearchCV(XGBClassifier( max_depth=3, min_child_weight=1, gamma=0.5, subsample=0.6, colsample_bytree=0.6, objective= 'binary:logistic', #邏輯回歸損失函數 scale_pos_weight=1, reg_alpha=0, reg_lambda=1, seed=27 ), param_grid=parameters,scoring='roc_auc') clf.fit(X_train, y_train) print(clf.best_params_) y_pre= clf.predict(X_test) y_pro= clf.predict_proba(X_test)[:,1] print "AUC Score : %f" % metrics.roc_auc_score(y_test, y_pro) print"Accuracy : %.4g" % metrics.accuracy_score(y_test, y_pre)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

輸出特征重要性

import pandas as pd import matplotlib.pylab as plt feat_imp = pd.Series(clf.booster().get_fscore()).sort_values(ascending=False) #新版需要轉換成dict or list #feat_imp = pd.Series(dict(clf.get_booster().get_fscore())).sort_values(ascending=False) #plt.bar(feat_imp.index, feat_imp) feat_imp.plot(kind='bar', title='Feature Importances') plt.ylabel('Feature Importance Score') plt.show()

python風控評分卡建模和風控常識

https://study.163.com/course/introduction.htm?courseId=1005214003&utm_campaign=commission&utm_source=cp-400000000398149&utm_medium=share

?

總結

以上是生活随笔為你收集整理的xgboost使用调参的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。