Skip to content

Commit

Permalink
fix: adding more flexibility
Browse files Browse the repository at this point in the history
  • Loading branch information
bokajgd committed Jun 16, 2023
1 parent fca7264 commit 014ba4e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 9 additions & 9 deletions src/psycop/common/model_evaluation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
from collections.abc import Iterable, MutableMapping, Sequence
from datetime import date, datetime
from pathlib import Path
from typing import Any, Dict, Optional, Union
from typing import Any, Optional, Union

import dill as pkl
import numpy as np
import pandas as pd
import wandb
from psycop.common.global_utils.paths import PSYCOP_PKG_ROOT
from pydantic import BaseModel as PydanticBaseModel
from pydantic import Extra
from sklearn.pipeline import Pipeline

import wandb
from psycop.common.global_utils.paths import PSYCOP_PKG_ROOT

TEST_PLOT_PATH = PSYCOP_PKG_ROOT / "test_utils" / "test_outputs" / "plots_from_tests"
TEST_PLOT_PATH.mkdir(parents=True, exist_ok=True)

Expand Down Expand Up @@ -362,7 +361,7 @@ def find_best_run_in_dir(
run_group: str,
lookahead_window: int,
dir_path: Path,
) -> Dict:
) -> dict:
"""Function for finding best performing model run in a directory containing multiple runs.
Args:
Expand All @@ -374,14 +373,15 @@ def find_best_run_in_dir(
str: Name of best performing run.
"""

dir = dir_path / run_group
dir = dir_path / run_group

parquet_files = [file for file in os.listdir(dir) if file.endswith(f"{lookahead_window}.parquet")]
parquet_files = [
file for file in os.listdir(dir) if file.endswith(f"{lookahead_window}.parquet")
]

dfs = []

for file in parquet_files:

parquet_file = os.path.join(dir, file)
df = pd.read_parquet(parquet_file)
dfs.append(df)
Expand All @@ -390,4 +390,4 @@ def find_best_run_in_dir(

best_run = concatenated_df.loc[concatenated_df["roc_auc"].idxmax()].to_dict()

return best_run
return best_run
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from pathlib import Path

import plotnine as pn

from psycop.common.model_evaluation.utils import find_best_run_in_dir
from psycop.projects.forced_admission_inpatient.utils.best_runs import Run, RunGroup

Expand All @@ -20,7 +19,6 @@ class BestRun:
POS_RATE = 0.05



DEV_GROUP_NAME = "bonnetiere-coarrange"

# Best model on structured features
Expand All @@ -31,7 +29,7 @@ class BestRun:
)

# Exteracting name of run
BEST_RUN_NAME = BEST_RUN['run_name']
BEST_RUN_NAME = BEST_RUN["run_name"]


DEVELOPMENT_GROUP = RunGroup(name=DEV_GROUP_NAME)
Expand Down

0 comments on commit 014ba4e

Please sign in to comment.