After the article: http://blog.csdn.net/mmc2015/article/details/47304591
def xgboost_pred (train,labels,test):p arams = {}params["objective"] = "reg:linear" params["eta"] = 0.005params["Min_ Child_weight "] = 6params[" subsample "] = 0.7params[" Colsample_bytree "] = 0.7params[" scale_pos_weight "] = 1params[" Silent "] = 1params[" max_depth "] = 9 Plst = List (Params.items ()) #Using the rows for early stopping. offset = 4000num_rounds = 10000xgtest = Xgb. Dmatrix (test) #create a train and validation dmatrices Xgtrain = xgb. Dmatrix (Train[offset:,:], Label=labels[offset:]) Xgval = XGB. Dmatrix (Train[:offset,:], Label=labels[:offset]) #train using early stopping and predictwatchlist = [(Xgtrain, ' train '), (Xgval, ' Val ')] Model = Xgb.train (Plst, Xgtrain, Num_rounds, watchlist, early_stopping_rounds=120) preds1 = Model.predict (xgtest,ntree_ limit=model.best_iteration) #reverse train and labels and use different 5k for early stopping. # This adds very little to the score but it was an option if you were concerned about using all the data. Train = Train[::-1,:]labels = Np.log (labels[:: -1]) Xgtrain = XGB. Dmatrix (Train[offset:,:], Label=labels[offset:]) Xgval = XGB. Dmatrix (Train[:offset,:], label=labels[:offset]) watchlist = [(Xgtrain, ' Train '), (Xgval, ' val ')]model = Xgb.train (plst , Xgtrain, Num_rounds, watchlist, early_stopping_rounds=120) preds2 = Model.predict (xgtest,ntree_limit=model.best_ Iteration) #combine Predictions#since the metric only cares on relative rank we don ' t need to Averagepreds = (PREDS1) * *. 4 + (PREDS2) *8.6return Preds
(Code from Kaggle)
Code specific analysis have time to write, Welcome to spit Groove ....
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Machine learning in coding (Python): Building predictive models using Xgboost