README.md 2.79 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
- [`dask/`](./dask): examples using Dask for distributed training
23
- [simple_example.py](https://github.com/microsoft/LightGBM/blob/master/examples/python-guide/simple_example.py)
24
25
    - Construct Dataset
    - Basic train and predict
26
    - Eval during training
27
28
    - Early stopping
    - Save model to file
29
- [sklearn_example.py](https://github.com/microsoft/LightGBM/blob/master/examples/python-guide/sklearn_example.py)
30
    - Create data for learning with sklearn interface
31
32
    - Basic train and predict with sklearn interface
    - Feature importances with sklearn interface
33
    - Self-defined eval metric with sklearn interface
34
    - Find best parameters for the model with sklearn's GridSearchCV
35
- [advanced_example.py](https://github.com/microsoft/LightGBM/blob/master/examples/python-guide/advanced_example.py)
36
    - Construct Dataset
37
    - Set feature names
38
    - Directly use categorical features without one-hot encoding
39
40
    - Save model to file
    - Dump model to JSON format
41
    - Get feature names
42
    - Get feature importances
43
44
    - Load model to predict
    - Dump and load model with pickle
45
46
    - Load model file to continue training
    - Change learning rates during training
47
    - Change any parameters during training
48
49
    - Self-defined objective function
    - Self-defined eval metric
50
    - Callback function
51
- [logistic_regression.py](https://github.com/microsoft/LightGBM/blob/master/examples/python-guide/logistic_regression.py)
52
53
54
    - Use objective `xentropy` or `binary`
    - Use `xentropy` with binary labels or probability labels
    - Use `binary` only with binary labels
55
    - Compare speed of `xentropy` versus `binary`
56
- [plot_example.py](https://github.com/microsoft/LightGBM/blob/master/examples/python-guide/plot_example.py)
57
58
59
60
    - Construct Dataset
    - Train and record eval results for further plotting
    - Plot metrics recorded during training
    - Plot feature importances
61
    - Plot split value histogram
62
63
    - Plot one specified tree
    - Plot one specified tree with Graphviz
64
65
66
- [dataset_from_multi_hdf5.py](https://github.com/microsoft/LightGBM/blob/master/examples/python-guide/dataset_from_multi_hdf5.py)
  - Construct Dataset from multiple HDF5 files
  - Avoid loading all data into memory