text_plain_output_1.png
from category_encoders import TargetEncoder

from sklearn.compose import ColumnTransformer

from sklearn.impute import SimpleImputer

from sklearn.pipeline import Pipeline

from sklearn.preprocessing import LabelEncoder

from sklearn.preprocessing import MinMaxScaler

X_num = ['time_in_hospital', 'num_lab_procedures', 'num_procedures', 'num_medications', 'number_outpatient', 'number_emergency', 'number_inpatient', 'number_diagnoses']
X_cat = ['race', 'gender', 'age', 'admission_type_id', 'discharge_disposition_id', 'admission_source_id', 'max_glu_serum', 'A1Cresult', 'metformin', 'repaglinide', 'nateglinide', 'glimepiride', 'glipizide', 'glyburide', 'pioglitazone', 'rosiglitazone', 'insulin', 'change', 'diabetesMed', 'payer_code', 'medical_specialty']
X_diag = ['diag_1', 'diag_2', 'diag_3']
X_id = ['encounter_id', 'patient_nbr']

cat_pipeline = Pipeline([('imputer', SimpleImputer(strategy='most_frequent')), ('encoder', TargetEncoder())])
num_pipeline = Pipeline([('median imputer', SimpleImputer(strategy='median')), ('scaler', MinMaxScaler())])
diag_pipeline = Pipeline([('diag_pipeline', MapDiagnosis()), ('imputer', SimpleImputer(strategy='most_frequent')), ('encoder', TargetEncoder())])
id_pipeline = Pipeline([('encoder', patient_nbr_transformer()), ('scaler', MinMaxScaler())])
full_pipeline = ColumnTransformer(transformers=[('num', num_pipeline, X_num), ('cat', cat_pipeline, X_cat), ('id', id_pipeline, X_id), ('diag', diag_pipeline, X_diag)], remainder='drop')

le = LabelEncoder()
y_train_prepared = le.fit_transform(y_train)

X_train_prepared = full_pipeline.fit_transform(X_train, y_train_prepared)

X_test_prepared = full_pipeline.transform(X_test)
print(X_test_prepared.shape)