SynapseML icon indicating copy to clipboard operation
SynapseML copied to clipboard

Add LightGBM learners to MMLSpark

Open imatiach-msft opened this issue 9 years ago • 66 comments

Add LightGBM learners to MMLSpark as spark Estimators and Transformers We can generate Java wrappers through SWIG

imatiach-msft avatar Oct 27 '17 17:10 imatiach-msft

Hello,

Where can I find the package com.microsoft.ml.lightgbm?

Thank you for this great project!

David082 avatar Jan 19 '18 05:01 David082

Hi @David082, We will be uploading it to maven central as soon as we are done. It is currently in a private repository. Thank you, Ilya

imatiach-msft avatar Jan 25 '18 14:01 imatiach-msft

@David082 I have checked in the code to generate the SWIG wrappers into the LightGBM repo. To build, you just need to run:

mkdir build ; cd build cmake -DUSE_SWIG=ON .. make -j4

This will generate a jar file containing the LightGBM c_api wrapped by SWIG. You will need to load the native .so files as in the lightgbm branch before calling into the Java API. I am currently working on the LightGBM estimator in the lightGBM branch in mmlspark - I am currently doing performance testing and optimization.

imatiach-msft avatar Feb 01 '18 05:02 imatiach-msft

@David082 LightGBM is now available in maven central: https://repo.maven.apache.org/maven2/com/microsoft/ml/lightgbm/lightgbmlib/ You can import it with sbt via: "com.microsoft.ml.lightgbm" % "lightgbmlib" % "2.0.120"

imatiach-msft avatar Feb 06 '18 22:02 imatiach-msft

@imatiach-msft Thank you!

David082 avatar Feb 09 '18 06:02 David082

Hello,

I saw that LightGBMClassifier has been added LightGBMClassifier Do you plan to add also a LightGBMRegressor ?

Thank you very much

ezerhoun avatar Feb 09 '18 16:02 ezerhoun

Yes, I will add a separate LightGBMRegressor in the near future, I think it should be trivial. I'm also going to extend the current classifier to support multiclass in addition to binary labels, this should be easy to do as well. Adding the ranker may take some planning and thought though in order to make it fit into the spark ecosystem.

imatiach-msft avatar Feb 09 '18 17:02 imatiach-msft

@imatiach-msft Thank you !

ezerhoun avatar Feb 09 '18 17:02 ezerhoun

@imatiach-msft great job with the classifier, thank you very much! We are waiting now for the regressor as well.

troszok avatar Feb 15 '18 08:02 troszok

@troszok Thanks! The classifier has been checked in and I have created a PR to add the regressor here: https://github.com/Azure/mmlspark/pull/249

imatiach-msft avatar Feb 21 '18 18:02 imatiach-msft

@troszok the LightGBM regressor has been merged into master, we would love to hear any feedback you might have for the interface and the parameters we currently expose - in my testing the LightGBMClassifier learner was 10-30% faster in execution time than spark's GBTClassifier and had 15% better AUC on the Higgs dataset

imatiach-msft avatar Feb 27 '18 21:02 imatiach-msft

@imatiach-msft Thank you for adding LightGBM regressor !

I am trying to train a LightGBM Quantile regressor. However, I don't see how to pass the quantile parameter (alpha parameter in LightGBM). Do you have an example of how to do it ?

ezerhoun avatar Mar 02 '18 07:03 ezerhoun

@ezerhoun thank you for the great feedback! I've created a PR which adds the alpha parameter for lightGBMRegressor and a pyspark notebook example for how to use lightGBM with quantile regression: https://github.com/Azure/mmlspark/pull/254 It's currently in code review. If you need to add more params but can't wait for us to add them to the learner you can also put the param=value inside the "application" parameter, eg:

df = ... reg = LightGBMRegressor(application='quantile alpha=0.1') model = reg.fit(df)

it must be in the format that lightgbm accepts

imatiach-msft avatar Mar 02 '18 19:03 imatiach-msft

@imatiach-msft Thank you for your quick reply and PR ! Moreover, I have couple of other questions:

  • I would like to use the jar produced by a PR, but after the PR being merged, the jar is deleted. Do you have an existing jar in https://mmlspark.azureedge.net/maven which contains the lastest code (SNAPSHOT) ?
  • Will it be possible to save a LightGBM model and load it using the python or java implementation (via SWIG) ?

ezerhoun avatar Mar 03 '18 21:03 ezerhoun

@ezerhoun Is the scenario to train in spark but score in a java environment? In that case, I think it is possible 1.) For now, you can use the maven coordinates that are produced through the build but you will need to add our resolver or repository (https://mmlspark.azureedge.net/maven) -- as soon as we have a new release you will be able to use coordinates from maven central as explained in the main page 2.) Yes, it should be possible - when you save the model in spark in one of the folders there will be a text file representing the model which you can then parse using either LightGBM's native C++ api, LightGBM's load model in python or R, or the load model in the Java jar that is in maven

imatiach-msft avatar Mar 05 '18 14:03 imatiach-msft

@ezerhoun for now, you can use the following options when running spark: --packages com.microsoft.ml.spark:mmlspark_2.11:0.11.dev31+1.gf23ab7852 --repositories https://mmlspark.azureedge.net/maven please let me know if you have questions or comments

imatiach-msft avatar Mar 05 '18 16:03 imatiach-msft

@imatiach-msft Thank you for your replies . Indeed the idea would be to train in Spark and test in Java. I don't know if it is the right place to ask but I have the following error :

Py4JJavaError: An error occurred while calling o673.fit.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 4 in stage 47.1 failed 4 times, most recent failure: Lost task 4.3 in stage 47.1 (TID 3569, 10.233.104.114, executor 33): java.lang.Exception: Network init call failed in LightGBM with error: Machine list file doesn't contain the local machine

Should I do as in LightGBM Parallel Learning Guide and create a mlist.txt

Thanks !

ezerhoun avatar Mar 05 '18 16:03 ezerhoun

@ezerhoun I believe I have figured out the issue, there was a bug in my new code. I've created a new build, will send you the new package when it is finished.

imatiach-msft avatar Mar 05 '18 22:03 imatiach-msft

@ezerhoun the fixed package is: --packages com.microsoft.ml.spark:mmlspark_2.11:0.11.dev31+1.g4ad3176c9 --repositories https://mmlspark.azureedge.net/maven.

imatiach-msft avatar Mar 06 '18 02:03 imatiach-msft

@imatiach-msft great news!!! I forgot to check the progress here. We will try to do POC with new model and we will let you know!

troszok avatar Mar 06 '18 09:03 troszok