"tests/git@developer.sourcefind.cn:tianlh/lightgbm-dcu.git" did not exist on "92a8741b9cb36a13d7232272e7052ca5e2fa04e6"
README.md 2.44 KB
Newer Older
1
Python-package Examples
2
3
=======================

4
Here is an example for LightGBM to use Python-package.
5

6
You should install LightGBM [Python-package](https://github.com/Microsoft/LightGBM/tree/master/python-package) first.
7

8
You also need scikit-learn, pandas, matplotlib (only for plot example), and scipy (only for logistic regression example) to run the examples, but they are not required for the package itself. You can install them with pip:
9

10
```
11
pip install scikit-learn pandas matplotlib scipy -U
12
13
14
```

Now you can run examples in this folder, for example:
15

16
17
18
```
python simple_example.py
```
19
20
21

Examples include:

22
23
24
25
26
27
28
- [simple_example.py](https://github.com/Microsoft/LightGBM/blob/master/examples/python-guide/simple_example.py)
    - Construct Dataset
    - Basic train and predict
    - Eval during training 
    - Early stopping
    - Save model to file
- [sklearn_example.py](https://github.com/Microsoft/LightGBM/blob/master/examples/python-guide/sklearn_example.py)
29
    - Create data for learning with sklearn interface 
30
31
    - Basic train and predict with sklearn interface
    - Feature importances with sklearn interface
32
    - Self-defined eval metric with sklearn interface
33
    - Find best parameters for the model with sklearn's GridSearchCV
34
35
- [advanced_example.py](https://github.com/Microsoft/LightGBM/blob/master/examples/python-guide/advanced_example.py)
    - Set feature names
36
    - Directly use categorical features without one-hot encoding
37
38
39
    - Dump model to json format
    - Get feature importances
    - Get feature names
40
41
    - Load model to predict
    - Dump and load model with pickle
42
43
    - Load model file to continue training
    - Change learning rates during training
44
    - Change any parameters during training
45
46
    - Self-defined objective function
    - Self-defined eval metric
47
    - Callback function
48
49
50
51
- [logistic_regression.py](https://github.com/Microsoft/LightGBM/blob/master/examples/python-guide/logistic_regression.py)
    - Use objective `xentropy` or `binary`
    - Use `xentropy` with binary labels or probability labels
    - Use `binary` only with binary labels
52
53
54
55
56
57
58
59
    - Compare speed of `xentropy` versus `binary`
- [plot_example.py](https://github.com/Microsoft/LightGBM/blob/master/examples/python-guide/plot_example.py)
    - Construct Dataset
    - Train and record eval results for further plotting
    - Plot metrics recorded during training
    - Plot feature importances
    - Plot one specified tree
    - Plot one specified tree with Graphviz