Spaces:
Running
Running
Update src/preprocess_utils.py
Browse files- src/preprocess_utils.py +30 -39
src/preprocess_utils.py
CHANGED
|
@@ -2133,6 +2133,13 @@ def preprocess_pipeline(df, target_col=None) -> pd.DataFrame:
|
|
| 2133 |
"HLA_mismatch_weighted",
|
| 2134 |
"OS_time_days",
|
| 2135 |
"OS_time_months",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2136 |
}
|
| 2137 |
|
| 2138 |
num_fill_cols = [c for c in num_cols if c not in keep_nan_numeric]
|
|
@@ -2180,43 +2187,7 @@ def preprocess_pipeline(df, target_col=None) -> pd.DataFrame:
|
|
| 2180 |
df["Hematological Diagnosis_Grouped"] = np.nan
|
| 2181 |
df["Hematological Diagnosis_Malignant"] = np.nan
|
| 2182 |
|
| 2183 |
-
|
| 2184 |
-
df,
|
| 2185 |
-
["Donor_gender", "Recipient_gender", "Source of cells", "Donor_type", "GVHD_Prophylaxis_Cat", "Conditioning_intensity"],
|
| 2186 |
-
min_non_null_fraction=0.05
|
| 2187 |
-
):
|
| 2188 |
-
df = add_chronic_gvhd_features(df)
|
| 2189 |
-
important_sparse_cols = [
|
| 2190 |
-
"HLAmatchratio",
|
| 2191 |
-
"HLA_Class_I_mismatch",
|
| 2192 |
-
"HLA_Class_II_mismatch",
|
| 2193 |
-
"HLA_total_match",
|
| 2194 |
-
"HLA_total_mismatch",
|
| 2195 |
-
"Donor_type",
|
| 2196 |
-
"Conditioning_intensity",
|
| 2197 |
-
"GVHD_Prophylaxis_Cat",
|
| 2198 |
-
"Source of cells",
|
| 2199 |
-
"Recipient_Blood group before HSCT_MergePlusMinus",
|
| 2200 |
-
"D_Blood group_MergePlusMinus",
|
| 2201 |
-
"R_Age_at_transplant",
|
| 2202 |
-
"D_Age_at_transplant",
|
| 2203 |
-
]
|
| 2204 |
-
df = add_missing_indicators(df, important_sparse_cols)
|
| 2205 |
-
else:
|
| 2206 |
-
chronic_cols = [
|
| 2207 |
-
"Female_to_Male",
|
| 2208 |
-
"PBSC",
|
| 2209 |
-
"BONE_MARROW",
|
| 2210 |
-
"CORD",
|
| 2211 |
-
"Older_Donor",
|
| 2212 |
-
"Older_Recipient",
|
| 2213 |
-
"HLA_mismatch_weighted",
|
| 2214 |
-
"DonorType_Source",
|
| 2215 |
-
"DonorType_Proph",
|
| 2216 |
-
"DonorType_Conditioning",
|
| 2217 |
-
]
|
| 2218 |
-
for c in chronic_cols:
|
| 2219 |
-
df[c] = np.nan
|
| 2220 |
|
| 2221 |
# Do NOT globally replace UNKNOWN_TOKEN across all columns
|
| 2222 |
# Only coerce numeric columns where needed
|
|
@@ -2224,9 +2195,29 @@ def preprocess_pipeline(df, target_col=None) -> pd.DataFrame:
|
|
| 2224 |
if pd.api.types.is_numeric_dtype(df[col]):
|
| 2225 |
df[col] = pd.to_numeric(df[col], errors="coerce")
|
| 2226 |
|
| 2227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2228 |
|
| 2229 |
-
|
| 2230 |
# Ensure newly added categorical model features exist with sensible defaults
|
| 2231 |
categorical_defaults = {
|
| 2232 |
"Recipient_gender": UNKNOWN_TOKEN,
|
|
|
|
| 2133 |
"HLA_mismatch_weighted",
|
| 2134 |
"OS_time_days",
|
| 2135 |
"OS_time_months",
|
| 2136 |
+
"CD34_DOSE_X10E6_PER_KG",
|
| 2137 |
+
"CMV_RECIPIENT_POSITIVE",
|
| 2138 |
+
"CMV_DONOR_POSITIVE",
|
| 2139 |
+
"ALEMTUZUMAB_USED",
|
| 2140 |
+
"ATG_USED",
|
| 2141 |
+
"T_CELL_DEPLETION",
|
| 2142 |
+
"CD34_SELECTION",
|
| 2143 |
}
|
| 2144 |
|
| 2145 |
num_fill_cols = [c for c in num_cols if c not in keep_nan_numeric]
|
|
|
|
| 2187 |
df["Hematological Diagnosis_Grouped"] = np.nan
|
| 2188 |
df["Hematological Diagnosis_Malignant"] = np.nan
|
| 2189 |
|
| 2190 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2191 |
|
| 2192 |
# Do NOT globally replace UNKNOWN_TOKEN across all columns
|
| 2193 |
# Only coerce numeric columns where needed
|
|
|
|
| 2195 |
if pd.api.types.is_numeric_dtype(df[col]):
|
| 2196 |
df[col] = pd.to_numeric(df[col], errors="coerce")
|
| 2197 |
|
| 2198 |
+
# Always build engineered features; add_chronic_gvhd_features already has
|
| 2199 |
+
# per-feature >=5% guards, so a sparse column no longer nulls the whole block.
|
| 2200 |
+
df = add_chronic_gvhd_features(df)
|
| 2201 |
+
important_sparse_cols = [
|
| 2202 |
+
"HLAmatchratio",
|
| 2203 |
+
"HLA_Class_I_mismatch",
|
| 2204 |
+
"HLA_Class_II_mismatch",
|
| 2205 |
+
"HLA_total_match",
|
| 2206 |
+
"HLA_total_mismatch",
|
| 2207 |
+
"Donor_type",
|
| 2208 |
+
"Conditioning_intensity",
|
| 2209 |
+
"GVHD_Prophylaxis_Cat",
|
| 2210 |
+
"Source of cells",
|
| 2211 |
+
"Recipient_Blood group before HSCT_MergePlusMinus",
|
| 2212 |
+
"D_Blood group_MergePlusMinus",
|
| 2213 |
+
"R_Age_at_transplant",
|
| 2214 |
+
"D_Age_at_transplant",
|
| 2215 |
+
]
|
| 2216 |
+
df = add_missing_indicators(df, important_sparse_cols)
|
| 2217 |
+
|
| 2218 |
+
print("POST-FIX check:",
|
| 2219 |
+
df[["PBSC", "BONE_MARROW", "CORD"]].notna().mean().round(3).to_dict())
|
| 2220 |
|
|
|
|
| 2221 |
# Ensure newly added categorical model features exist with sensible defaults
|
| 2222 |
categorical_defaults = {
|
| 2223 |
"Recipient_gender": UNKNOWN_TOKEN,
|