Merge pull request #482 from terrytangyuan/patch-1

Added xgboost demo using caret into README and added more explanation in the demo
This commit is contained in:
Tong He 2015-09-11 11:20:37 -07:00
commit dd3126735b
2 changed files with 9 additions and 5 deletions

View File

@ -1,6 +1,7 @@
XGBoost R Feature Walkthrough 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) * [Cutomize loss function, and evaluation metric](custom_objective.R)
* [Boosting from existing prediction](boost_from_prediction.R) * [Boosting from existing prediction](boost_from_prediction.R)
* [Predicting using first n trees](predict_first_ntree.R) * [Predicting using first n trees](predict_first_ntree.R)

View File

@ -22,11 +22,14 @@ df[,AgeCat:= as.factor(ifelse(Age > 30, "Old", "Young"))]
df[,ID:=NULL] df[,ID:=NULL]
#-------------Basic Training using XGBoost in caret Library----------------- #-------------Basic Training using XGBoost in caret Library-----------------
# set up control parameters for caret::train # Set up control parameters for caret::train
# here we use 10-fold cross-validation, repeating twice # 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) fitControl <- trainControl(method = "cv", number = 10, repeats = 2, search = "random")
# train a xgbTree model using caret::train # train a xgbTree model using caret::train
model <- train(factor(Improved)~., data = df, method = "xgbTree", trControl = fitControl) 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 # See model results
print(model) print(model)