Parameters-tuning.md 2.86 KB
Newer Older
1
2
# Parameters Tuning

Guolin Ke's avatar
Guolin Ke committed
3
4
5
6
This is a page contains all parameters in LightGBM.

***List of other Helpful Links***
* [Parameters](./Parameters.md)
7
* [Python API](./Python-API.rst)
Guolin Ke's avatar
Guolin Ke committed
8

9
## Tune Parameters for the Leaf-wise (Best-first) Tree
Guolin Ke's avatar
Guolin Ke committed
10

11
LightGBM uses the [leaf-wise](./Features.md) tree growth algorithm, while many other popular tools use depth-wise tree growth. Compared with depth-wise growth, the leaf-wise algorithm can convenge much faster. However, the leaf-wise growth may be over-fitting if not used with the appropriate parameters. 
Guolin Ke's avatar
Guolin Ke committed
12

aamster's avatar
aamster committed
13
To get good results using a leaf-wise tree, these are some important parameters:
Guolin Ke's avatar
Guolin Ke committed
14

aamster's avatar
aamster committed
15
1. ```num_leaves```. This is the main parameter to control the complexity of the tree model. Theoretically, we can set ```num_leaves = 2^(max_depth) ``` to convert from depth-wise tree. However, this simple conversion is not good in practice. The reason is, when number of leaves are the same, the leaf-wise tree is much deeper than depth-wise tree. As a result, it may be over-fitting. Thus, when trying to tune the ```num_leaves```, we should let it be smaller than ```2^(max_depth)```. For example, when the ```max_depth=6``` the depth-wise tree can get good accuracy, but setting ```num_leaves``` to ```127``` may cause over-fitting, and setting it to ```70``` or ```80``` may get better accuracy than depth-wise. Actually, the concept ```depth``` can be forgotten in leaf-wise tree, since it doesn't have a correct mapping from ```leaves``` to ```depth```. 
Guolin Ke's avatar
Guolin Ke committed
16

aamster's avatar
aamster committed
17
2. ```min_data_in_leaf```. This is a very important parameter to deal with over-fitting in leaf-wise tree. Its value depends on the number of training data and ```num_leaves```. Setting it to a large value can avoid growing too deep a tree, but may cause under-fitting. In practice, setting it to hundreds or thousands is enough for a large dataset. 
Guolin Ke's avatar
Guolin Ke committed
18
19

3. ```max_depth```. You also can use ```max_depth``` to limit the tree depth explicitly. 
Guolin Ke's avatar
Guolin Ke committed
20
21


22
## For Faster Speed
Guolin Ke's avatar
Guolin Ke committed
23

aamster's avatar
aamster committed
24
25
* Use bagging by setting ```bagging_fraction``` and ```bagging_freq``` 
* Use feature sub-sampling by setting ```feature_fraction```
Guolin Ke's avatar
Guolin Ke committed
26
27
* Use small ```max_bin```
* Use ```save_binary``` to speed up data loading in future learning
28
* Use parallel learning, refer to [Parallel Learning Guide](./Parallel-Learning-Guide.rst).
Guolin Ke's avatar
Guolin Ke committed
29

30
## For Better Accuracy
Guolin Ke's avatar
Guolin Ke committed
31

Preston Parry's avatar
Preston Parry committed
32
* Use large ```max_bin``` (may be slower)
Guolin Ke's avatar
Guolin Ke committed
33
* Use small ```learning_rate``` with large ```num_iterations```
Preston Parry's avatar
Preston Parry committed
34
* Use large ```num_leaves```(may cause over-fitting)
Guolin Ke's avatar
Guolin Ke committed
35
36
37
* Use bigger training data
* Try ```dart```

38
## Deal with Over-fitting
Guolin Ke's avatar
Guolin Ke committed
39
40
41
42
43
44
45
46
47

* Use small ```max_bin```
* Use small ```num_leaves```
* Use ```min_data_in_leaf``` and ```min_sum_hessian_in_leaf```
* Use bagging by set ```bagging_fraction``` and ```bagging_freq``` 
* Use feature sub-sampling by set ```feature_fraction```
* Use bigger training data
* Try ```lambda_l1```, ```lambda_l2``` and ```min_gain_to_split``` to regularization
* Try ```max_depth``` to avoid growing deep tree