image_output_1.png
from feature_engine.imputation import MeanMedianImputer

import pandas as pd # tt processing, CSV file I/O (e.g. pd.read_csv)

df_train = pd.read_csv('../input/spaceship-titanic/train.csv')
df_train

df_test = pd.read_csv('../input/spaceship-titanic/test.csv')
df_test

df_train.isnull().sum()

df_train.isnull().mean() * 100

df_test.isnull().mean() * 100

tt = pd.concat([df_train.drop('Transported', axis=1), df_test])
tt

tt['Age_cat_'] = pd.cut(tt.Age, bins=[0, 5, 12, 18, 50, 150], labels=['Toddler/Baby', 'Child', 'Teen', 'Adult', 'Elderly'])
tt['Age_cat_']

numerical = tt.select_dtypes(exclude=['object', 'category']).columns.to_list()
numerical

tt.isnull().mean() * 100

tt = tt.set_index('PassengerId')
tt

categorical = tt.select_dtypes(['object', 'category']).columns.to_list()
categorical

numerical = tt.select_dtypes(exclude=['object', 'category']).columns.to_list()
numerical

from feature_engine.imputation import MeanMedianImputer
median_imputer = MeanMedianImputer(imputation_method='median', variables=numerical)
median_imputer.fit(tt[numerical])

tt_num = median_imputer.transform(tt[numerical])
tt_num

from feature_engine import transformation as vt
power_tf = vt.YeoJohnsonTransformer(variables=['RoomService', 'FoodCourt', 'ShoppingMall', 'Spa', 'VRDeck', 'sum_exp_', 'mean_exp_'])
power_tf.fit(tt_num)
tt_num = power_tf.transform(tt_num)
tt_num