Expose metrics in C/Python APIs
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.
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 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 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
@travisbrady were you able to reproduce the NDCG score with the change suggested by @guolinke
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.