import xgboost as xgb
import pandas as pd
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import roc_auc_score

iris = load_iris()
X,y = iris.data,iris.target
col = iris.target_names
train_x,valid_x,train_y,valid_y = train_test_split(X,y,test_size = 0.3,random_state=420)
parameters = {
    # 'max_depth':[5,10,15,20,25],
    # 'learning_rate':[0.01,0.02,0.05,0.1,0.15],
    # 'n_eatimators':[500,1000,2000,3000,5000],
    # 'min_child_weight':[0,2,5,10,20],
    # 'max_delta_step':[0,0.2,0.6,1,2],
    # 'subsample':[0.6,0.7,0.8,0.85,0.95],
    # 'colsample_bytree':[0.5,0.6,0.7,0.8,0.9],
    # 'reg_alpha':[0,0.25,0.5,0.75,1],
    # 'reg_lamba':[0.2,0.4,0.6,0.8,1],
    # 'scale_pos_weight':[0.2,0.4,0.6,0.8,1]
    'max_depth': [5, 10],
    'learning_rate': [0.01, 0.02],
    'n_eatimators': [500, 1000],
    'min_child_weight': [0, 2],
    'max_delta_step': [0, 0.2],
    'subsample': [0.6, 0.7],
    'colsample_bytree': [0.5, 0.6],
    'reg_alpha': [0, 0.25],
    'reg_lamba': [0.2, 0.4],
    'scale_pos_weight': [0.2, 0.4]
}

xlf = xgb.XGBClassifier(max_depth = 10,
                        learning_rate = 0.01,
                        n_estimators = 2000,
                        silent = True,
                        objective = 'multi:softmax',
                        num_class = 3,
                        nthread = -1,
                        gamma = 0,
                        min_child_weight = 1,
                        max_delta_step = 0,
                        subsample = 0.85,
                        colsample_bytree = 0.7,
                        colsample_bylevel = 1,
                        reg_alpha = 0,
                        reg_lambda=1,
                        scale_pos_weight=1,
                        seed = 0,
                        missing=None)
gs = GridSearchCV(xlf,param_grid = parameters, scoring = 'accuracy',cv = 3)
gs.fit(train_x,train_y)

print("Best score:%0.3f"% gs.best_score_)
print("Best parameters set: %s"% gs.best_params_)

