Add ranking metrics to philanthropy validate - #250
Merged
Merged
Conversation
Precision/recall/F1 at a fixed 0.5 threshold hid a usable model whenever the target was rare: a holdout with a 9% positive rate could show a recall near zero while the same model still ranked donors well. validate now also reports average precision, the base rate, a 10-row decile table (hit rate and lift over the base rate per decile), and a top-N hit rate/capture line via a new --top-n flag (count or percentage, default top 10%). The old metrics are now labelled "at threshold 0.5" so they read as one view rather than the whole picture. Also fixed train, score, and validate scoring on a bare numpy array after fitting on named columns, which made every run of score or validate print an sklearn "does not have valid feature names" warning.
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.
What
validatenow reports, alongside the existing precision/recall/F1/ROC-AUC:--top-nflag that takes a row count or a percentage like10%(default: top 10% of rows)Precision, recall, and F1 are now labelled "at threshold 0.5" so they read as one view of the model rather than the whole picture.
Also fixed
train,score, andvalidatescoring on a bare numpy array after the model was fit on named columns, which made every run ofscoreorvalidateprint an sklearn "X does not have valid feature names" warning. All three now pass the feature DataFrame through consistently.Why
On a holdout where only about 9% of donors were the target outcome, the old report showed recall of 0.107 at the fixed 0.5 threshold, which reads as a broken model. The same model had a decile-1 hit rate of 0.420 (4.5x lift over the base rate) and an average precision of 0.459, meaning it ranked donors usefully even though it looked broken under a single fixed threshold. The old report had no way to see that. This mirrors how a real prospect list gets used: an analyst mails or calls the top N donors by score, not everyone above 0.5, so hit rate and lift in that top slice is the number that actually matters.
Example output
On a holdout with a 12.4% positive rate:
How tested
test_cli_validate_reports_ranking_metrics,test_cli_validate_top_n_accepts_count_and_percentage, andtest_cli_train_score_validate_do_not_warn_on_feature_namestotests/test_cli.py.make ci: 2198 passed, 30 skipped, required coverage 92%, actual 98.36%.make riskcov: risk-tier floor 93%, actual 98%.docs/how-to/use_the_cli.mdanddocs/reference/cli.mdwith the new flag and example output, and added a CHANGELOG entry under Unreleased.