Add LightGBM learners to MMLSpark
Add LightGBM learners to MMLSpark as spark Estimators and Transformers We can generate Java wrappers through SWIG
Hello,
Where can I find the package com.microsoft.ml.lightgbm?
Thank you for this great project!
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
@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.
@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 Thank you!
Hello,
I saw that LightGBMClassifier has been added LightGBMClassifier Do you plan to add also a LightGBMRegressor ?
Thank you very much
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 Thank you !
@imatiach-msft great job with the classifier, thank you very much! We are waiting now for the regressor as well.
@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
@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 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 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 Thank you for your quick reply and PR ! Moreover, I have couple of other questions:
- I would like to use the
jarproduced by a PR, but after the PR being merged, thejaris 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 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
@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 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 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.
@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 great news!!! I forgot to check the progress here. We will try to do POC with new model and we will let you know!