Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tianqi Chen - XGBoost: Overview and Latest News...

Data Science LA
June 04, 2016
780k

Tianqi Chen - XGBoost: Overview and Latest News - LA Meetup Talk

Data Science LA

June 04, 2016
Tweet

More Decks by Data Science LA

Transcript

  1. Outline • Introduction • What does XGBoost learn • What

    can XGBoost System do for you • Impact of XGBoost
  2. Machine Learning Algorithms and Common Use-cases • Linear Models for

    Ads Clickthrough • Factorization Models for Recommendation • Deep Neural Nets for Images, Audios etc. • Trees for tabular data: the secret sauce in machine learning ◦ Anomaly detection ◦ Ads clickthrough ◦ Fraud detection ◦ Insurance risk estimation ◦ ...
  3. Regression Tree Input: age, gender, occupation, … age < 15

    is male? +2 -1 +0.1 Y N Y N Does the person like computer games prediction score in each leaf • Regression tree (also known as CART) • This is what it would looks like for a commercial system
  4. When Trees forms a Forest (Tree Ensembles) age < 15

    is male? +2 -1 +0.1 Y N Y N Use Computer Daily Y N +0.9 -0.9 tree1 tree2 f( ) = 2 + 0.9= 2.9 f( )= -1 - 0.9= -1.9
  5. Variant of algorithms to learn Tree Ensembles • Random Forest

    (Breiman 1997) ◦ RandomForest packages in R and python • Gradient Tree Boosting (Friedman 1999) ◦ R GBM ◦ sklearn.ensemble.GradientBoostingClassifier • Gradient Tree Boosting with Regularization (variant of original GBM) ◦ Regularized Greedy Forest (RGF) ◦ XGBoost
  6. Learning Trees : Advantage and Challenges • Advantages of tree-based

    methods ▪ Highly accurate: almost half of data science challenges are won by tree based methods. ▪ Easy to use: invariant to input scale, get good performance with little tuning. ▪ Easy to interpret and control • Challenges on learning tree(ensembles) ▪ Control over-fitting ▪ Improve training speed and scale up to larger dataset
  7. What is XGBoost • A Scalable System for Learning Tree

    Ensembles ◦ Model improvement ▪ Regularized objective for better model ◦ Systems optimizations ▪ Out of core computing ▪ Parallelization ▪ Cache optimization ▪ Distributed computing ◦ Algorithm improvements ▪ Sparse aware algorithm ▪ Weighted approximate quantile sketch. • In short, faster tool for learning better models
  8. Outline • Introduction • What does XGBoost learn • What

    can XGBoost do for you • Impact of XGBoost
  9. What does XGBoost learn • A self-contained derivation of general

    gradient boosting algorithm • Resembles the original GBM derivation by Friedman • Only preliminary of calculus is needed
  10. ML 101: Elements of Supervised Learning • Model: how to

    make prediction ▪ Linear model: • Parameters: the things we need to learn from data ▪ Linear model: • Objective Function: ▪ Linear model: , Training Loss measures how well model fit on training data Regularization, measures complexity of model
  11. Elements of Tree Learning • Model: assuming we have K

    trees • Objective Training Loss measures how well model fit on training data Regularization, measures complexity of trees Space of Regression trees
  12. Trade off in Learning • Optimizing training loss encourages predictive

    models ▪ Fitting well in training data at least get you close to training data which is hopefully close to the underlying distribution • Optimizing regularization encourages simple models ▪ Simpler models tends to have smaller variance in future predictions, making prediction stable Training Loss measures how well model fit on training data Regularization, measures complexity of trees
  13. Define Complexity of a Tree age < 15 is male?

    Y N Y N Leaf 1 Leaf 2 Leaf 3 q( ) = 1 q( ) = 3 w1=+2 w2=0.1 w3=-1 The structure of the tree The leaf weight of the tree
  14. Define Complexity of a Tree (cont’) Number of leaves L2

    norm of leaf scores age < 15 is male? Y N Y N Leaf 1 Leaf 2 Leaf 3 w1=+2 w2=0.1 w3=-1 Objective in XGBoost
  15. How can we learn tree ensembles • Objective: • We

    can not use methods such as SGD. • Solution: Additive Training (Boosting) ▪ Start from constant prediction, add a new function each time Model at training round t New function Keep functions added in previous round
  16. Additive Training This is what we need to decide in

    round t Goal: find to minimize this This is usually called residual from previous round • How do we decide which f to add: Optimize the objective! • The prediction at round t is • Consider square loss
  17. Taylor Expansion Approximation of Loss • Goal • Take Taylor

    expansion of the objective ▪ Recall ▪ Define • In terms of square loss
  18. Our New Goal • Objective, with constants removed • Define

    the instance set in leaf j as ▪ Regroup the objective by leaf ▪ This is sum of T independent quadratic function
  19. The Structure Score • Two facts about single variable quadratic

    function • Let us define • Assume the structure of tree ( q(x) ) is fixed, the optimal weight in each leaf, and the resulting objective value are This measures how good a tree structure is!
  20. The Structure Score Calculation Instance index 1 2 3 4

    5 g1, h1 g2, h2 g3, h3 g4, h4 g5, h5 gradient statistics age < 15 is male? Y N Y N The smaller the score is, the better the structure is
  21. Searching Algorithm for Single Tree • Enumerate the possible tree

    structures q • Calculate the structure score for the q, using the scoring eq. • Find the best tree structure, and use the optimal leaf weight • But… there can be infinite possible tree structures..
  22. Greedy Learning of the Tree • In practice, we grow

    the tree greedily ▪ Start from tree with depth 0 ▪ For each leaf node of the tree, try to add a split. The change of objective after adding the split is ▪ Remaining question: how do we find the best split? the score of left child the score of right child the score of if we do not split The complexity cost by introducing additional leaf
  23. Efficient Finding of the Best Split • What is the

    gain of a split rule ? Say is age • All we need is sum of g and h in each side, and calculate • Left to right linear scan over sorted instance is enough to decide the best split along the feature g1, h1 g4, h4 g2, h2 g5, h5 g3, h3
  24. Pruning and Regularization • Recall the gain of split, it

    can be negative! ▪ When the training loss reduction is smaller than regularization ▪ Trade-off between simplicity and predictiveness • Pre-stopping ▪ Stop split if the best split have negative gain ▪ But maybe a split can benefit future splits.. • Post-Prunning ▪ Grow a tree to maximum depth, recursively prune all the leaf splits with negative gain
  25. XGBoost Model Recap • A regularized objective for better generalization

    • Additive solution for generic objective function • Structure score to search over structures. • Why take all the pain in deriving the algorithm ◦ Know your model ◦ Clear definitions in algorithm offers clear and extendible modules in software
  26. Outline • Introduction • What does XGBoost learn • What

    can XGBoost do for you • Impact of XGBoost
  27. What can XGBoost can do for you • Push the

    limit of computation resources to solve one problem ◦ Gradient tree boosting • Automatic handle missing value • Interactive Feature analysis • Extendible system for more functionalities • Deployment on the Cloud
  28. Getting Started (python) import xgboost as xgb # read in

    data dtrain = xgb.DMatrix('demo/data/agaricus.txt.train') dtest = xgb.DMatrix('demo/data/agaricus.txt.test') # specify parameters via map param = {'max_depth':2, 'eta':1, 'silent':1, 'objective':'binary:logistic' } num_round = 2 bst = xgb.train(param, dtrain, num_round) # make prediction preds = bst.predict(dtest)
  29. Getting Started (R) # load data data(agaricus.train, package='xgboost') data(agaricus.test, package='xgboost')

    train <- agaricus.train test <- agaricus.test # fit model bst <- xgboost(data = train$data, label = train$label, max.depth = 2, eta = 1, nround = 2, nthread = 2, objective = "binary:logistic") # predict pred <- predict(bst, test$data)
  30. Automatic Missing Value Handling age < 20 is male? Y

    N Y N default default Example Age Gender X1 ? male X2 15 ? X3 25 female X1 X2 X3 Data XGBoost learns the best direction for missing values
  31. Inspect Your Models bst <- xgboost(data = train$data, label =

    train$label, max.depth = 2, eta = 1, nthread = 2, nround = 2, objective = "binary:logistic") xgb.plot.tree(feature_names = agaricus.train$data@Dimnames[[2]], model = bst)
  32. Feature Importance Analysis bst <- xgboost(data = train$data, label =

    train$label, max.depth = 2, eta = 1, nthread = 2, nround = 2,objective = "binary:logistic") importance_matrix <- xgb.importance(agaricus.train$data@Dimnames[[2]], model = bst) xgb.plot.importance(importance_matrix)
  33. Automatic Sparse Data Optimization • Useful for categorical encoding and

    other cases (e.g. Bag of words) • User do not need to worry about large sparse matrices Impact of sparse aware vs basic algorithm on allstate dataset
  34. Extendibility: Customized Objective Function • XGBoost solves wide range of

    objectives ◦ Binary classification ◦ Ranking ◦ Multi-class classification • Customize objective function loglossobj <- function(preds, dtrain) { # dtrain is the internal format of the training data # We extract the labels from the training data labels <- getinfo(dtrain, "label") # We compute the 1st and 2nd gradient, as grad and hess preds <- 1/(1 + exp(-preds)) grad <- preds - labels hess <- preds * (1 - preds) # Return the result as a list return(list(grad = grad, hess = hess)) } model <- xgboost(data = train$data, label = train$label, nrounds = 2, objective = loglossobj, eval_metric = "error")
  35. Extendibility: Modular Library • Plugin system ◦ Enable you to

    plugin customized data loader, metrics, learners ◦ Optionally build with some of the plugins ◦ https://github.com/dmlc/xgboost/tree/master/plugin • Modular library to for even more extensions ◦ Recent pull request of supporting DART (dropout in tree boosting) ▪ Reuse of all data loading and tree learning modules ▪ Around 300 lines of additional code
  36. Extendibility on Language API: Early Stopping bst <- xgb.cv(data =

    train$data, label = train$label, nfold = 5, nrounds = 20, objective = "binary:logistic", early.stop.round = 3, maximize = FALSE) ## [0] train-error:0.000921+0.000343 test-error:0.001228+0.000686 ## [1] train-error:0.001228+0.000172 test-error:0.001228+0.000686 ## [2] train-error:0.000653+0.000442 test-error:0.001075+0.000875 ## [3] train-error:0.000422+0.000416 test-error:0.000767+0.000940 ## [4] train-error:0.000192+0.000429 test-error:0.000460+0.001029 ## [5] train-error:0.000192+0.000429 test-error:0.000460+0.001029 ## [6] train-error:0.000000+0.000000 test-error:0.000000+0.000000 ## [7] train-error:0.000000+0.000000 test-error:0.000000+0.000000 ## [8] train-error:0.000000+0.000000 test-error:0.000000+0.000000 ## [9] train-error:0.000000+0.000000 test-error:0.000000+0.000000 ## Stopping. Best iteration: 7 This feature is contributed by users, because they can directly hack the R/python API easily:) Many more similar examples
  37. Faster Training Speed via Parallel Training Minimum benchmark from szilard/benchm-ml

    • Push limit of machine in all cases • Low memory footprint • Hackable native codes ◦ Instead of everything in backend ◦ Early-stopping ◦ Checkpointing ◦ Customizable objective
  38. XGBoost with Out of Core Computation • Impact of out

    of core optimizations • On a single EC2 machine with two SSD
  39. Distributed XGBoost vs Other Solutions End to end cost include

    data loading Per iteration cost exclude data loading • 16 AWS m3.2xlarge machines • Missing data points are due to out of memory
  40. What can XGBoost cannot do for you • Feature engineering

    • Hyper parameter tuning • A lot more cases ...
  41. What XGBoost does instead... • Deeply integrate with existing ecosystem

    • Directly interact with native data structures • Expose native standard APIs
  42. Unix Philosophy in Machine Learning • XGBoost focuses on one

    thing and does its best for you. • In order to be useful for the users, XGBoost also have to be open and integrate well with other systems by common interface. • Always be modular, extendible, so we can keep up to the state of art easily.
  43. Outline • Introduction • What does XGBoost learn • What

    does XGBoost System provide • Impact of XGBoost
  44. Industry Use cases • Used by Google, MS Azure, Tencent,

    Alibaba, .. • Quotes from some users: ◦ Hanjing Su from Tencent data platform team: "We use distributed XGBoost for click through prediction in wechat shopping and lookalikes. The problems involve hundreds millions of users and thousands of features. XGBoost is cleanly designed and can be easily integrated into our production environment, reducing our cost in developments." ◦ CNevd from autohome.com ad platform team: "Distributed XGBoost is used for click through rate prediction in our display advertising, XGBoost is highly efficient and flexible and can be easily used on our distributed platform, our ctr made a great improvement with hundred millions samples and millions features due to this awesome XGBoost"
  45. Machine Learning Challenge Winning Solutions • The most frequently used

    tool by data science competition winners ◦ 17 out of 29 winning solutions in kaggle last year used XGBoost ◦ Solve wide range of problems: store sales prediction; high energy physics event classification; web text classification; customer behavior prediction; motion detection; ad click through rate prediction; malware classification; product categorization; hazard risk prediction; massive online course dropout rate prediction • Present and Future of KDDCup. Ron Bekkerman (KDDCup 2015 chair): “Something dramatic happened in Machine Learning over the past couple of years. It is called XGBoost – a package implementing Gradient Boosted Decision Trees that works wonders in data classification. Apparently, every winning team used XGBoost, mostly in ensembles with other classifiers. Most surprisingly, the winning teams report very minor improvements that ensembles bring over a single well- configured XGBoost..” • A lot contributions from the kaggle community
  46. DMLC: Distributed Machine Learning Common • DMLC is a group

    to collaborate on open-source machine learning projects, with a goal of making cutting-edge large-scale machine learning widely available. The contributors includes researchers, PhD students and data scientists who are actively working on the field. • for effective tree boosting • for deep learning • Support of other core system components for largescale ML
  47. Contribute to XGBoost and Other DMLC Projects • Contribute code

    to improve the package • Create tutorials on how the usecases • Share your experience ◦ Awesome XGBoost https://github.com/dmlc/xgboost/tree/master/demo
  48. Acknowledgement • XGBoost Committers ◦ Tong He, Bing Xu, Michael

    Benesty, Yuan Tang, Scott Lundberg • Contributors of XGBoost • Users in the XGBoost Community