Skip to content

Improve uplift_at_k validation and add top-k markers to prediction plots#224

Closed
RiukaRin wants to merge 10 commits into
maks-sh:devfrom
RiukaRin:vm/additional
Closed

Improve uplift_at_k validation and add top-k markers to prediction plots#224
RiukaRin wants to merge 10 commits into
maks-sh:devfrom
RiukaRin:vm/additional

Conversation

@RiukaRin

@RiukaRin RiukaRin commented Mar 18, 2026

Copy link
Copy Markdown

This PR improves metric robustness and visualization usability in three related areas:

Added explicit validation in uplift_at_k(..., strategy="overall") to ensure the selected top-k slice contains both treatment and control samples.
Previously, this edge case could return nan
Now it raises a clear ValueError with guidance
Extended plot_uplift_preds with a new optional k parameter
Supports k as float in (0, 1) or int in [1, n_samples].
Draws top-k threshold markers (vertical lines) for treatment, control, and uplift histograms.
Adds validation for invalid k values/types.
Tightened metric tests by replacing broad pytest.raises(Exception) with explicit pytest.raises(ValueError) where appropriate.
Also updated API docs for plot_uplift_preds to mention top-k threshold markers.

Verification Process
Validated syntax of updated files via Python compile checks (py_compile)
Ran direct runtime checks for new uplift_at_k behavior:

  • Confirmed ValueError is raised for top-k slices missing one group in overall strategy
  • Confirmed valid scenarios still return finite values.

Added/updated tests:
New test for uplift_at_k empty-group edge case
New/updated tests for plot_uplift_preds(k=...), including invalid k cases
Updated exception-type assertions in metric tests to specific ValueError

Note: full pytest run is pending in a project-compatible environment (not available in the current environment due to pytest/scikit-learn setup mismatch for full test execution)

Additional info
This PR is intentionally structured as three logical commits:

  1. metric validation (uplift_at_k)
  2. visualization feature (plot_uplift_preds + docs/tests)
  3. stricter exception-type tests in metrics

@RiukaRin RiukaRin closed this Jul 8, 2026
@RiukaRin
RiukaRin deleted the vm/additional branch July 8, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants