Repository navigation
fix(model_selection): grid_search never selects an unscored setting (sweep 11-25) - #7
Merged
Merged
Conversation
…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).
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.
grid_searchpicked an unscored setting whenever it came first in the grid (CPZ-Lab/cpzai#3175, filed against cpz-ai 4.44.0, whosecpz.portfoliois a shim overcpz_quant.portfolio).Per issue
if best is None or score > best[1]: once a NaN score was "best",x > nanis 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.resultsand are never selected. No finite score, or an empty grid, raisesValueError. A score that is not a real number or None (a string, an array, a bool) is a scorer bug and raisesTypeErrornaming 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.pyreproduces 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_searchand a new helper beside it.Tests
tests/test_grid_search_unscored.py: 11 passed.Release note for Chris
Release as cpz-quant 1.3.0 together with #8 and #9 (not 1.2.1);
CHANGELOG.mdhas an Unreleased entry. cpz-ai picks it up once itscpz-quantfloor is raised to 1.3.0 (CPZ-Lab/cpz-py#78). No version was changed here.