LightGBM icon indicating copy to clipboard operation
LightGBM copied to clipboard

[Feature] Python Bindings for LightGBM

Open chivee opened this issue 10 years ago • 13 comments

Hi all, we have tentative plan on extending LightGBM to python users. please share us your opinions.

chivee avatar Oct 18 '16 05:10 chivee

I think this should be a great step forward with adoption, of course it should be also pretty easy to install and use. These are the features I think you should consider for python support:

  • install via pip
  • scikit learn interface so people can use fit/predict and have a drop-in replacement for xgboost/GBM
  • Loading/Saving models via pickle or dedicated methods

ParadoxShmaradox avatar Oct 18 '16 12:10 ParadoxShmaradox

Agree with ParadoxShmaradox. And for me earlystopping would be a great feature to have.

yychenca avatar Oct 18 '16 21:10 yychenca

@ParadoxShmaradox @yychenca , we can break its procedure into two several phrases: 1. python bindings. 2 scikit-learn(or other popular framework) interface.

As for model (de)serialization, cross validation, and early stopping seems to be another popular features we should move on. I'll open issues for this features.

chivee avatar Oct 19 '16 03:10 chivee

Want to add, that something like xgboosts scale_pos_weight to handle imbalanced classes, or even better an Implementation of Example-Dependent Cost-Sensitive would be very interesting http://nbviewer.jupyter.org/github/albahnsen/CostSensitiveClassification/blob/master/doc/tutorials/tutorial_edcs_credit_scoring.ipynb

geoHeil avatar Oct 19 '16 15:10 geoHeil

I think we need a way to create the LightGBM binary format directly from a NumPy array instead of having to do an expensive write&read to CSV/SVMLight. For really big datasets (eg. Kaggle Bosch Competition) it can take an hour to read and write CSVs, so something like this (functionality similar to xgboost.DMatrix()) would be excellent.

mxbi avatar Oct 19 '16 16:10 mxbi

I think user-define loss and eval function is also important

modkzs avatar Oct 20 '16 13:10 modkzs

@chivee Thank you chivee. I had a chance to try LightGBM with a dataset of 180k rows and 30 features for a regression problem. The training completed in 8 seconds as compared to 52 secs by XGBoost using comparable parameters, 63 leaves vs 8 depths. And the accuracy of LIghtGBM (L1/MAE ) was even a bit better. Truly impressed!!

Noticed that early stopping has already been added and I'll probably give it another try soon.

Anyways, great job!

yychenca avatar Oct 20 '16 15:10 yychenca

A quick wrapper for LightGBM: https://github.com/ArdalanM/pyLightGBM It still dump input to svm format before training on.

ArdalanM avatar Oct 20 '16 16:10 ArdalanM

@ArdalanM , thank you ardalanM , that will be very helpful!

chivee avatar Oct 21 '16 03:10 chivee

Hi guys, a simple Python binding using Ctype can be found at https://github.com/Microsoft/LightGBM/blob/master/tests/c_api_test/test.py,

Any feedback to the bindings will be great.

chivee avatar Nov 10 '16 07:11 chivee

Existing python binding is great, but I would love to be able to replace existing algorithms in the pipeline and most likely they have scikit-learn interface.

At least on the level of:

    1. fit
    1. transform
    1. fit_transform
    1. predict
    1. predict_proba

ternaus avatar Nov 15 '16 19:11 ternaus

refer to #94. The basic class are finished. I think we can base on these classes to implement sklearn-liked interfaces.

guolinke avatar Nov 24 '16 11:11 guolinke

Hi, All,

the branch of python-package is merged, refer to https://github.com/Microsoft/LightGBM/tree/master/python-package Welcome to have a try and provide feedback and issues.

guolinke avatar Dec 01 '16 08:12 guolinke