README.md 1.89 KB
Newer Older
1
2
3
Python Package Examples
=======================

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
29
30
31
32
- [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)
    - Basic train and predict with sklearn interface
    - Feature importances with sklearn interface
- [advanced_example.py](https://github.com/Microsoft/LightGBM/blob/master/examples/python-guide/advanced_example.py)
    - Set feature names
33
    - Directly use categorical features without one-hot encoding
34
35
36
    - Dump model to json format
    - Get feature importances
    - Get feature names
37
38
    - Load model to predict
    - Dump and load model with pickle
39
40
41
42
    - Load model file to continue training
    - Change learning rates during training
    - Self-defined objective function
    - Self-defined eval metric
43
    - Callback function
44
45
46
47
48
- [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
    - Compare speed of `xentropy` versus `binary`