【集成學習】sklearn中xgboot模塊中fit函數參數詳解(fit model for train data)


參數解釋,后續補上。

  1 # -*- coding: utf-8 -*-
  2 """
  3 ###############################################################################
  4 # 作者:wanglei5205
  5 # 郵箱:wanglei5205@126.com
  6 # 代碼:http://github.com/wanglei5205
  7 # 博客:http://cnblogs.com/wanglei5205
  8 # 目的:學習xgboost的XGBClassifier函數
  9 # 官方API文檔:http://xgboost.readthedocs.io/en/latest/python/python_api.html#module-xgboost.training
 10 ###############################################################################
 11 """
 12 ### load module
 13 from sklearn import datasets
 14 from sklearn.model_selection import train_test_split
 15 from xgboost import XGBClassifier
 16 
 17 ### load datasets
 18 digits = datasets.load_digits()
 19 
 20 ### data analysis
 21 print(digits.data.shape)
 22 print(digits.target.shape)
 23 
 24 ### data split
 25 x_train,x_test,y_train,y_test = train_test_split(digits.data,
 26                                                  digits.target,
 27                                                  test_size = 0.3,
 28                                                  random_state = 33)
 29 
 30 ### fit model for train data
 31 # fit函數參數:eval_set=[(x_test,y_test)]  評估數據集,list類型
 32 # fit函數參數:eval_metric="mlogloss"      評估標准(多分類問題,使用mlogloss作為損失函數)
 33 # fit函數參數:early_stopping_rounds= 10   如果模型的loss十次內沒有減小,則提前結束模型訓練
 34 # fit函數參數:verbose = True              True顯示,False不顯示
 35 model = XGBClassifier()
 36 model.fit(x_train,
 37           y_train,
 38           eval_set = [(x_test,y_test)],  # 評估數據集
 39 
 40           eval_metric = "mlogloss",
 41           early_stopping_rounds = 10,
 42           verbose = True)
 43 
 44 ### make prediction for test data
 45 y_pred = model.predict(x_test)
 46 
 47 ### model evaluate
 48 from sklearn.metrics import accuracy_score
 49 accuracy = accuracy_score(y_test,y_pred)
 50 print("accuarcy: %.2f%%" % (accuracy*100.0))
 51 """
 52 95.0%
 53 """


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM