Skip to content

Commit

Permalink
Merge pull request dmlc#482 from terrytangyuan/patch-1
Browse files Browse the repository at this point in the history
Added xgboost demo using caret into README and added more explanation in the demo
  • Loading branch information
hetong007 committed Sep 11, 2015
2 parents 0fe182d + 424bcc0 commit dd31267
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion R-package/demo/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
XGBoost R Feature Walkthrough
====
* [Basic walkthrough of wrappers](basic_walkthrough.R)
* [Basic walkthrough of wrappers](basic_walkthrough.R)
* [Train a xgboost model from caret library](caret_wrapper.R)
* [Cutomize loss function, and evaluation metric](custom_objective.R)
* [Boosting from existing prediction](boost_from_prediction.R)
* [Predicting using first n trees](predict_first_ntree.R)
Expand Down
11 changes: 7 additions & 4 deletions R-package/demo/caret_wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ df[,AgeCat:= as.factor(ifelse(Age > 30, "Old", "Young"))]
df[,ID:=NULL]

#-------------Basic Training using XGBoost in caret Library-----------------
# set up control parameters for caret::train
# here we use 10-fold cross-validation, repeating twice
fitControl <- trainControl(method = "cv", number = 10, repeats = 2)
# Set up control parameters for caret::train
# Here we use 10-fold cross-validation, repeating twice, and using random search for tuning hyper-parameters.
fitControl <- trainControl(method = "cv", number = 10, repeats = 2, search = "random")
# train a xgbTree model using caret::train
model <- train(factor(Improved)~., data = df, method = "xgbTree", trControl = fitControl)

# Instead of tree for our boosters, you can also fit a linear regression or logistic regression model using xgbLinear
# model <- train(factor(Improved)~., data = df, method = "xgbLinear", trControl = fitControl)

# See model results
print(model)
print(model)

0 comments on commit dd31267

Please sign in to comment.