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

4
5
6
7
8
9
Here is an example for LightGBM to use python package.

***You should install lightgbm (both c++ and python verion) first.***

For the installation, check the wiki [here](https://github.com/Microsoft/LightGBM/wiki/Installation-Guide).

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

12
```
13
pip install scikit-learn pandas matplotlib -U
14
15
16
```

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

18
19
20
```
python simple_example.py
```
21
22
23

Examples include:

24
25
26
27
28
29
30
31
32
33
34
- [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
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
43
44
    - Load model file to continue training
    - Change learning rates during training
    - Self-defined objective function
    - Self-defined eval metric
45
    - Callback function