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

feat: fill configs and write to disk on load #438

Closed
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"python.analysis.typeCheckingMode": "strict",
"python.testing.pytestArgs": [
"."
"psycop"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ validation_outcome_col_name = "outcome"
[trainer.preprocessing_pipeline.*.age_filter]
@preprocessing = "age_filter"
min_age = 4
max_age = 99
age_col_name = "pred_age"

[trainer.task]
Expand Down
23 changes: 21 additions & 2 deletions psycop/common/model_training_v2/config/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,31 @@
def load_baseline_config(config_path: Path) -> BaselineSchema:
"""Loads the baseline config from disk and resolves it."""
cfg = Config().from_disk(config_path)
resolved = BaselineRegistry.resolve(cfg)

# Fill with defaults and write to disk if relevant
filled = BaselineRegistry.fill(cfg, validate=False)
resolved = BaselineRegistry.resolve(filled)

# Writing to disk happens after resolution, to ensure that the
# config is valid
if cfg != filled:
filled.to_disk(config_path)

return BaselineSchema(**resolved)


def load_hyperparam_config(config_path: Path) -> dict[str, Any]:
"""Loads the baseline config from disk and resolves it."""
cfg = Config().from_disk(config_path)
resolved = BaselineRegistry.resolve(cfg)

# Fill with defaults and write to disk if relevant
filled = BaselineRegistry.fill(cfg, validate=False)
resolved = BaselineRegistry.resolve(filled)

# Writing to disk happens after resolution, to ensure that the
# config is valid
if cfg != filled:
filled.to_disk(config_path)

resolved = BaselineRegistry.resolve(filled)
return resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
[model]
@estimator_steps = "logistic_regression_suggester"
C = {"low": 0.1, "high": 1.0, "logarithmic": "True"}
l1_ratio = {"low": 0.01, "high": 1.0, "logarithmic": "True"}
solvers = ["saga"]
penalties = ["l1","l2","elasticnet"]

[model.C]
low = 0.1
high = 1.0
logarithmic = "True"

[model.l1_ratio]
low = 0.01
high = 1.0
logarithmic = "True"
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def apply(self, data: PolarsFrame) -> pd.DataFrame:


@BaselineRegistry.preprocessing.register("baseline_preprocessing_pipeline")
class BaselinePreprocessingPipeline(
PreprocessingPipeline,
): # TODO: #406 Does registering this into a registry remove protocol checking? E.g. the __init__ method does not adhered to PreprocessingPipeline
class BaselinePreprocessingPipeline(PreprocessingPipeline):
def __init__(self, *args: PresplitStep) -> None:
self.steps = list(args)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

@BaselineRegistry.preprocessing.register("age_filter")
class AgeFilter(PresplitStep):
def __init__(self, min_age: int, max_age: int, age_col_name: str):
def __init__(
self,
min_age: int,
max_age: int = 999,
age_col_name: str = "pred_age",
):
self.min_age = min_age
self.max_age = max_age
self.age = pl.col(age_col_name)
Expand Down
Loading