feat(scoring): expose HH_pd/CG_pd + PKB score conversion (0.6.0) - #17
Merged
Conversation
…mula (0.6.0) Per PKB: the LightGBM booster's predict output is a probability of default (*_pd), not a score. Convert to their scoring band via int(round(500 + 50 * log2((1 - pd) / pd))), clipping pd to (eps, 1 - eps) to avoid log2 blowing up on 0/1. NaN/None pd yields None score. Response schema per row now carries four fields when scoring is enabled: HH_pd, HH_score, CG_pd, CG_score. Both fields for a model are omitted together when that model path is not configured. BREAKING CHANGE: the meaning of HH_score / CG_score changed. Previously these were the raw booster output (float 0..1). Now they are integer PKB score bands. Consumers that parsed the old *_score as a probability need to switch to *_pd; consumers that need the integer band can keep reading *_score but must accept int instead of float.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Per PKB (Абай): the LightGBM booster's
predictoutput is a probability of default (*_pd), not a scoring band. Response now exposes both — raw*_pdand converted*_score— instead of only the raw value under the*_scorename (which was confusing).Per-row response fields when scoring is enabled:
HH_pd,CG_pd— raw booster output (float 0..1)HH_score,CG_score— integer PKB band,int(round(500 + 50 * log2((1 - pd) / pd)))Formula source: exact PKB expression from the ticket handoff. Clipping pd to
(1e-6, 1 - 1e-6)prevents log2 from blowing up on 0/1; NaN/None pd yields None score.Version bump
0.5.1 → 0.6.0(BREAKING:*_scorefield is now an integer band, not a raw float).Files touched
src/kz_scoring_api/scoring.py— addedpd_to_score, splitHH_KEY/CG_KEYintoHH_PD_KEY/HH_SCORE_KEY/CG_PD_KEY/CG_SCORE_KEY,score_rowswrites both fields.test_scoring.py,test_lookup.py,test_endpoints.py. NewTestPdToScorecovers half/low/high/0/1/NaN/None.pyproject.tomlbump.Test plan
pytest tests/— 93 passed locally (LightGBM real-model test skipped for missing dep, works in CI).docker-image.ymlpublishesghcr.io/aggregion/kz-scoring-api:v0.6.0.cr.selcloud.ru/aggregion/main/kz-scoring-api:v0.6.0.v0.6.0-models(models COPY layer) on top of the CI-producedv0.6.0, replace the current baked artifact.Consumer impact
The change is breaking only in one direction:
HH_score/CG_scoretype changed float → int, and its meaning changed from raw probability → integer band. A caller who relied on the old float value should switch toHH_pd/CG_pd.