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