gbdt_train.py 570 B

123456789101112131415161718192021
  1. #coding=utf-8
  2. #coding:utf-8
  3. #-*- coding:utf-8 -*-
  4. import numpy as np
  5. from sklearn.ensemble import GradientBoostingClassifier
  6. from sklearn.model_selection import train_test_split
  7. from sklearn.datasets import load_wine
  8. wine = load_wine()
  9. Xtrain, Xtest, Ytrain, Ytest = train_test_split(wine.data,wine.target,test_size=0.3)
  10. #print (X,y)
  11. #默认参数
  12. #Accuracy : 0.9856
  13. #AUC Score (Train): 0.862264
  14. gbm1 = GradientBoostingClassifier( n_estimators=500,max_depth=10,max_features='sqrt', random_state=10)
  15. gbm1.fit(Xtrain,Ytrain)
  16. print("gbdt1",gbm1.score(Xtest,Ytest))