Skip to content

fix(model_selection): grid_search never selects an unscored setting (sweep 11-25) - #7

Merged
chris-cpz merged 2 commits into
mainfrom
fix/sweep1125-sdk-options
Nov 29, 2026
Merged

chris-cpz merged 2 commits into
mainfrom
fix/sweep1125-sdk-options

Conversation

@chris-cpz

@chris-cpz chris-cpz commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

grid_search picked an unscored setting whenever it came first in the grid (CPZ-Lab/cpzai#3175, filed against cpz-ai 4.44.0, whose cpz.portfolio is a shim over cpz_quant.portfolio).

Per issue

Issue Verdict What was wrong Fix
CPZ-Lab/cpzai#3175 FIXED if best is None or score > best[1]: once a NaN score was "best", x > nan is False for every real score, so the search returned the first (unscored) setting. Reversing the grid picked the scored one. An empty grid returned {} with a fabricated score of 0.0. Scores that are None, NaN or inf stay in results and are never selected. No finite score, or an empty grid, raises ValueError. A score that is not a real number or None (a string, an array, a bool) is a scorer bug and raises TypeError naming the setting (review follow-up, second commit).

Fixes CPZ-Lab/cpzai#3175

Verified real by: on origin/main (7abc99b), a grid {"cash": [True, False]} with a scorer that returns NaN for the all-cash book returned {'cash': True} with score nan; reversed, it returned {'cash': False} with 0.666. tests/test_grid_search_unscored.py reproduces this: 10 of its 11 tests fail on origin/main (the reversed-order case passes there, as the reporter found).

This file is in the portfolio area the quant-optim sweep group also works in; the change is limited to grid_search and a new helper beside it.

Tests

  • tests/test_grid_search_unscored.py: 11 passed.
  • Full suite: 744 passed, 736 skipped.

Release note for Chris

Release as cpz-quant 1.3.0 together with #8 and #9 (not 1.2.1); CHANGELOG.md has an Unreleased entry. cpz-ai picks it up once its cpz-quant floor is raised to 1.3.0 (CPZ-Lab/cpz-py#78). No version was changed here.

…sweep 11-25)

An unscored (NaN) first setting stayed "best" for the whole search because
NaN compares False against every score, so the pick depended on grid
order. Settings whose score is None, NaN or inf stay in results and are
never selected; no finite score, or an empty grid, raises ValueError
instead of returning a blank best or a score of 0.0.
chris-cpz pushed a commit that referenced this pull request Nov 25, 2026
…_search

grid_search passes returns straight to cross_validate, which now accepts
Polars and pandas frames, so it needs no conversion of its own. Keeps the
grid_search body untouched next to the open grid_search fix (PR #7).
…cored setting (sweep 11-25)

Only None, NaN and inf mark a setting unscored. A string, array or bool
score raises TypeError naming the setting instead of being skipped.
chris-cpz pushed a commit that referenced this pull request Nov 25, 2026
…_search

grid_search passes returns straight to cross_validate, which now accepts
Polars and pandas frames, so it needs no conversion of its own. Keeps the
grid_search body untouched next to the open grid_search fix (PR #7).
@chris-cpz
chris-cpz merged commit c96c82d into main Nov 29, 2026
0 of 5 checks passed
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.

1 participant