-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeatures.py
More file actions
30 lines (25 loc) · 915 Bytes
/
features.py
File metadata and controls
30 lines (25 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Optional composite features — extend as the group finalises predictors."""
from __future__ import annotations
import pandas as pd
def add_optional_features(df: pd.DataFrame) -> pd.DataFrame:
"""
Placeholder for derived variables (e.g. counts, ratios).
Returns a copy with new columns; no-op if you add nothing below.
"""
out = df.copy()
# Example (uncomment when variables exist and are agreed):
# out["chronic_count"] = out[["cond1", "cond2"]].sum(axis=1)
return out
def list_numeric_predictors(
df: pd.DataFrame,
id_col: str,
exclude: frozenset[str],
) -> list[str]:
"""All numeric columns suitable for sklearn, excluding ID and outcome-related names."""
cols = []
for c in df.columns:
if c == id_col or c in exclude:
continue
if pd.api.types.is_numeric_dtype(df[c]):
cols.append(c)
return sorted(cols)