Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return hyper->value dict from hyperparam search #16

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions rlevaluation/hypers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ def select_best_hypers(

rng = np.random.default_rng(0)
out = bootstrap_hyper_selection(rng, score_per_seed, statistic.value, prefer.value, threshold)
config = {
col: df[col][out.best_idx] for col in cols
}

return HyperSelectionResult(
best_configuration=df.row(out.best_idx),
best_configuration=config,
best_score=out.best_score,

uncertainty_set_configurations=[
df.row(idx) for idx in out.uncertainty_set_idxs
{col: df[col][int(idx)] for col in cols}
for idx in out.uncertainty_set_idxs
],
uncertainty_set_probs=out.uncertainty_set_probs,
sample_stat=out.sample_stat,
Expand All @@ -72,10 +76,10 @@ def select_best_hypers(
)

class HyperSelectionResult(NamedTuple):
best_configuration: tuple[Any, ...]
best_configuration: dict[str, Any]
best_score: float

uncertainty_set_configurations: list[tuple[Any, ...]]
uncertainty_set_configurations: list[dict[str, Any]]
uncertainty_set_probs: np.ndarray
sample_stat: float
ci: tuple[float, float]
Expand Down
6 changes: 3 additions & 3 deletions rlevaluation/hypers/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ def pretty_print_hyper_selection_result(result: HyperSelectionResult, d: DataDef
if len(result.uncertainty_set_probs) > 1:
out += 'Possible best configurations:\n'
out += '-----------------------------\n'
for i, hyper in enumerate(cols):
hyper_val = result.uncertainty_set_configurations[0][i]
for hyper in cols:
hyper_val = result.uncertainty_set_configurations[0][hyper]
if isinstance(hyper_val, float) and np.isnan(hyper_val): continue
ws = 4 + col_len - len(hyper)
out += f'{hyper}:' + ' ' * ws

for config in result.uncertainty_set_configurations:
out += f'{config[i]} '
out += f'{config[hyper]} '

out += '\n'

Expand Down
2 changes: 1 addition & 1 deletion tests/test_hypers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ def test_select_best_hypers():
d = data_definition(hyper_cols=['alpha'])

best = select_best_hypers(test_data, 'result', Preference.high, data_definition=d)
assert best.best_configuration[0] == 0.01
assert best.best_configuration['alpha'] == 0.01