You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> *Windows*user will need to install [Rtools](http://cran.r-project.org/bin/windows/Rtools/) first.
47
+
> *Windows*users will need to install [Rtools](http://cran.r-project.org/bin/windows/Rtools/) first.
48
48
49
49
### CRAN version
50
50
@@ -97,7 +97,7 @@ train <- agaricus.train
97
97
test<-agaricus.test
98
98
```
99
99
100
-
> In the real world, it would be up to you to make this division between `train` and `test` data. The way to do it is out of the purpose of this article, however `caret` package may [help](http://topepo.github.io/caret/splitting.html).
100
+
> In the real world, it would be up to you to make this division between `train` and `test` data. The way to do it is out of scope for this article, however `caret` package may [help](http://topepo.github.io/caret/data-splitting.html).
101
101
102
102
Each variable is a `list` containing two things, `label` and `data`:
103
103
@@ -141,7 +141,7 @@ dim(test$data)
141
141
## [1] 1611 126
142
142
```
143
143
144
-
This dataset is very small to not make the **R** package too heavy, however **XGBoost** is built to manage huge dataset very efficiently.
144
+
This dataset is very small to not make the **R** package too heavy, however **XGBoost** is built to manage huge datasets very efficiently.
145
145
146
146
As seen below, the `data` are stored in a `dgCMatrix` which is a *sparse* matrix and `label` vector is a `numeric` vector (`{0,1}`):
147
147
@@ -171,7 +171,7 @@ This step is the most critical part of the process for the quality of our model.
171
171
172
172
We are using the `train` data. As explained above, both `data` and `label` are stored in a `list`.
173
173
174
-
In a *sparse* matrix, cells containing `0` are not stored in memory. Therefore, in a dataset mainly made of `0`, memory size is reduced. It is very usual to have such dataset.
174
+
In a *sparse* matrix, cells containing `0` are not stored in memory. Therefore, in a dataset mainly made of `0`, memory size is reduced. It is very common to have such a dataset.
175
175
176
176
We will train decision tree model using the following parameters:
**XGBoost** offers a way to group them in a `xgb.DMatrix`. You can even add other meta data in it. It will be useful for the most advanced features we will discover later.
213
+
**XGBoost** offers a way to group them in a `xgb.DMatrix`. You can even add other meta data in it. This will be useful for the most advanced features we will discover later.
**XGBoost** has several features to help you to view how the learning progress internally. The purpose is to help you to set the best parameters, which is the key of your model quality.
228
+
**XGBoost** has several features to help you view the learning progress internally. The purpose is to help you to set the best parameters, which is the key of your model quality.
229
229
230
-
One of the simplest way to see the training progress is to set the `verbose` option (see below for more advanced technics).
230
+
One of the simplest way to see the training progress is to set the `verbose` option (see below for more advanced techniques).
Both `xgboost` (simple) and `xgb.train` (advanced) functions train models.
362
362
363
-
One of the special feature of `xgb.train` is the capacity to follow the progress of the learning after each round. Because of the way boosting works, there is a time when having too many rounds lead to an overfitting. You can see this feature as a cousin of cross-validation method. The following techniques will help you to avoid overfitting or optimizing the learning time in stopping it as soon as possible.
363
+
One of the special features of `xgb.train` is the capacity to follow the progress of the learning after each round. Because of the way boosting works, there is a time when having too many rounds lead to overfitting. You can see this feature as a cousin of a cross-validation method. The following techniques will help you to avoid overfitting or optimizing the learning time in stopping it as soon as possible.
364
364
365
-
One way to measure progress in learning of a model is to provide to **XGBoost** a second dataset already classified. Therefore it can learn on the first dataset and test its model on the second one. Some metrics are measured after each round during the learning.
365
+
One way to measure progress in the learning of a model is to provide to **XGBoost** a second dataset already classified. Therefore it can learn on the first dataset and test its model on the second one. Some metrics are measured after each round during the learning.
366
366
367
-
> in some way it is similar to what we have done above with the average error. The main difference is that below it was after building the model, and now it is during the construction that we measure errors.
367
+
> in some way it is similar to what we have done above with the average error. The main difference is that above it was after building the model, and now it is during the construction that we measure errors.
368
368
369
369
For the purpose of this example, we use `watchlist` parameter. It is a list of `xgb.DMatrix`, each of them tagged with a name.
**XGBoost** has computed at each round the same average error metric than seen above (we set `nrounds` to 2, that is why we have two lines). Obviously, the `train-error` number is related to the training dataset (the one the algorithm learns from) and the `test-error` number to the test dataset.
383
+
**XGBoost** has computed at each round the same average error metric seen above (we set `nrounds` to 2, that is why we have two lines). Obviously, the `train-error` number is related to the training dataset (the one the algorithm learns from) and the `test-error` number to the test dataset.
384
384
385
385
Both training and test error related metrics are very similar, and in some way, it makes sense: what we have learned from the training dataset matches the observations from the test dataset.
386
386
387
-
If with your own dataset you have not such results, you should think about how you divided your dataset in training and test. May be there is something to fix. Again, `caret` package may [help](http://topepo.github.io/caret/splitting.html).
387
+
If with your own dataset you do not have such results, you should think about how you divided your dataset in training and test. May be there is something to fix. Again, `caret` package may [help](http://topepo.github.io/caret/data-splitting.html).
388
388
389
389
For a better understanding of the learning progression, you may want to have some specific metric or even use multiple evaluation metrics.
Until now, all the learnings we have performed were based on boosting trees. **XGBoost** implements a second algorithm, based on linear boosting. The only difference with previous command is `booster = "gblinear"` parameter (and removing `eta` parameter).
406
+
Until now, all the learnings we have performed were based on boosting trees. **XGBoost** implements a second algorithm, based on linear boosting. The only difference with the previous command is `booster = "gblinear"` parameter (and removing `eta` parameter).
In this specific case, *linear boosting* gets slightly better performance metrics than decision trees based algorithm.
418
+
In this specific case, *linear boosting* gets slightly better performance metrics than a decision tree based algorithm.
419
419
420
-
In simple cases, it will happen because there is nothing better than a linear algorithm to catch a linear link. However, decision trees are much better to catch a non linear link between predictors and outcome. Because there is no silver bullet, we advise you to check both algorithms with your own datasets to have an idea of what to use.
420
+
In simple cases, this will happen because there is nothing better than a linear algorithm to catch a linear link. However, decision trees are much better to catch a non linear link between predictors and outcome. Because there is no silver bullet, we advise you to check both algorithms with your own datasets to have an idea of what to use.
Information can be extracted from `xgb.DMatrix` using `getinfo` function. Hereafter we will extract `label` data.
460
+
Information can be extracted from an `xgb.DMatrix` using `getinfo` function. Hereafter we will extract `label` data.
461
461
462
462
463
463
```r
@@ -489,7 +489,7 @@ You can dump the tree you learned using `xgb.dump` into a text file.
489
489
490
490
491
491
```r
492
-
xgb.dump(bst, with.stats=T)
492
+
xgb.dump(bst, with_stats=T)
493
493
```
494
494
495
495
```
@@ -522,7 +522,7 @@ xgb.plot.tree(model = bst)
522
522
523
523
Maybe your dataset is big, and it takes time to train a model on it? May be you are not a big fan of losing time in redoing the same task again and again? In these very rare cases, you will want to save your model and load it when required.
524
524
525
-
Hopefully for you, **XGBoost** implements such functions.
525
+
Helpfully for you, **XGBoost** implements such functions.
0 commit comments