README.md 2.48 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
- [advanced_example.py](https://github.com/Microsoft/LightGBM/blob/master/examples/python-guide/advanced_example.py)
35
    - Construct Dataset
36
    - Set feature names
37
    - Directly use categorical features without one-hot encoding
38
39
    - Save model to file
    - Dump model to JSON format
40
    - Get feature names
41
    - Get feature importances
42
43
    - Load model to predict
    - Dump and load model with pickle
44
45
    - Load model file to continue training
    - Change learning rates during training
46
    - Change any parameters during training
47
48
    - Self-defined objective function
    - Self-defined eval metric
49
    - Callback function
50
51
52
53
- [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
54
55
56
57
58
59
60
61
    - 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