text_html_output_1.png
from sklearn.compose import ColumnTransformer

from sklearn.preprocessing import Binarizer

from sklearn.preprocessing import KBinsDiscretizer

import pandas as pd

df = pd.read_csv('/kaggle/input/titanic/train.csv', usecols=['Age', 'Fare', 'Survived'])

df.dropna(inplace=True)

X = df.iloc[:, 1:]
y = df.iloc[:, 0]

kbin_age = KBinsDiscretizer(n_bins=15, encode='ordinal', strategy='quantile')
kbin_fare = KBinsDiscretizer(n_bins=15, encode='ordinal', strategy='quantile')

trf = ColumnTransformer([('first', kbin_age, [0]), ('second', kbin_fare, [1])])

X_train_trf = trf.fit_transform(X_train)
X_test_trf = trf.transform(X_test)

output = pd.DataFrame({'age': X_train['Age'], 'age_trf': X_train_trf[:, 0], 'fare': X_train['Fare'], 'fare_trf': X_train_trf[:, 1]})

output['age_labels'] = pd.cut(x=X_train['Age'], bins=trf.named_transformers_['first'].bin_edges_[0].tolist())
output['fare_labels'] = pd.cut(x=X_train['Fare'], bins=trf.named_transformers_['second'].bin_edges_[0].tolist())

df = pd.read_csv('/kaggle/input/titanic/train.csv')[['Age', 'Fare', 'SibSp', 'Parch', 'Survived']]

trf = ColumnTransformer([('bin', Binarizer(copy=False), ['family'])], remainder='passthrough')

X_train_trf = trf.fit_transform(X_train)
X_test_trf = trf.transform(X_test)

pd.DataFrame(X_train_trf, columns=['family', 'Age', 'Fare'])