Spaces:
Running
Running
Download modules/pre_processing.py from CLL-Prediction/web: direct link, hf CLI and curl.
- Browser
- Download file 1.64 kB
-
https://huggingface.co/spaces/CLL-Prediction/web/resolve/main/modules/pre_processing.py
- Command line
-
hf download hf://spaces/CLL-Prediction/web/modules/pre_processing.py
-
curl -L -o pre_processing.py https://huggingface.co/spaces/CLL-Prediction/web/resolve/main/modules/pre_processing.py
1.64 kB
| import pandas as pd | |
| from sklearn.preprocessing import StandardScaler, OneHotEncoder | |
| def pre_processing(input_df): | |
| scaler = StandardScaler() | |
| numeric_columns = ['Lymphocyte count', 'Sleep duration'] # UKB code: p30120_i0, p1160_i0 | |
| input_df[numeric_columns] = scaler.fit_transform(input_df[numeric_columns]) | |
| categorical_columns = ['Sex', 'Past chemotherapy treatment', 'Enlarged liver and spleen', 'Unusual blood test results', 'Smoking history', 'History of muscle & joint conditions', 'Metastasis'] | |
| input_df[categorical_columns] = input_df[categorical_columns].astype('category') | |
| # 理論上要用當初訓練模型的encoder, 但因為都是yes/no and sex, 直接映射 | |
| input_df['Sex'] = input_df['Sex'].map({'Male': 1, 'Female': 0}) # UKB code: p31 | |
| input_df['Past chemotherapy treatment'] = input_df['Past chemotherapy treatment'].map({'Yes': 1, 'No': 0}) # UKB code: Z926 | |
| input_df['Enlarged liver and spleen'] = input_df['Enlarged liver and spleen'].map({'Yes': 1, 'No': 0}) # UKB code: R16 | |
| input_df['Unusual blood test results'] = input_df['Unusual blood test results'].map({'Yes': 1, 'No': 0}) # UKB code: R79 | |
| input_df['Smoking history'] = input_df['Smoking history'].map({'Smoked on most or all days': 1, 'Smoked occasionally': 2, 'Just tried once or twice': 3, 'I have never smoked': 4}) # UKB code: p1249_i0 | |
| input_df['History of muscle & joint conditions'] = input_df['History of muscle & joint conditions'].map({'Yes': 1, 'No': 0}) # UKB code: Z873 | |
| input_df['Metastasis'] = input_df['Metastasis'].map({'Yes': 1, 'No': 0}) # UKB code: C78 | |
| return input_df |