LightGBM icon indicating copy to clipboard operation
LightGBM copied to clipboard

Expose metrics in C/Python APIs

Open travisbrady opened this issue 9 years ago • 5 comments

I'm using the LGBMRanker class via the sklearn API in Python to train a lambdamart model, but I'm seeing issues where the ndcg@10 computed by lgb is substantially greater than what is computed in pure Python using the code here: https://gist.github.com/mblondel/7337391#file-letor_metrics-py-L124

I need to compute ndcg in this way because I have a need to first compute it per-query and then average it over a variety of groups (defined by type of query, type of user, etc) so I can examine the ranker's performance within certain small segments of the overall population.

Is this possible? If so I'd love to help by submitting a PR if someone could provide a rough roadmap of where to start.

travisbrady avatar Sep 29 '17 01:09 travisbrady

You can define and use a custom metric coded in Python like here: https://github.com/Microsoft/LightGBM/blob/master/examples/python-guide/advanced_example.py#L149-L151

Laurae2 avatar Oct 01 '17 19:10 Laurae2

@Laurae2 Yes thank you, I know about that. But the goal here is actually not to define anything on my own, but rather to expose what Lightgbm is doing internally.

In my case I have the above referenced ndcg calculation in pure Python which disagrees with lightgbm, so I want to resolve that by using the lightgbm version everywhere.

travisbrady avatar Oct 03 '17 19:10 travisbrady

@travisbrady the ndcg calculation in LightGBM is consistent with XGBoost. The different with normal ndcg is the query with non positive docs. In such cases, LightGBM/XGBoost will give score 1 to that query, but in normal ndcg, it may give score 0 to that query. refer to: https://github.com/Microsoft/LightGBM/blob/master/src/metric/rank_metric.hpp#L98-L101

guolinke avatar Oct 26 '17 01:10 guolinke

@travisbrady were you able to reproduce the NDCG score with the change suggested by @guolinke

gulshan-gaurav avatar Dec 05 '18 17:12 gulshan-gaurav

The goal here was to expose metrics via the C-api (partially for performance reasons since Python tends to be much slower). Not necessarily to verify the computation itself.

travisbrady avatar Dec 07 '18 22:12 travisbrady