Machine learning in coding (Python): Building predictive models using Xgboost

Source: Internet
Author: User
Tags xgboost

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.