text_plain_output_4.png text_plain_output_3.png text_html_output_1.png text_plain_output_2.png text_plain_output_1.png
from sklearn.preprocessing import OrdinalEncoder

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

train_df = pd.read_csv('/kaggle/input/30-days-of-ml/train.csv')
test_df = pd.read_csv('/kaggle/input/30-days-of-ml/test.csv')

cat_features = [feature for feature in train_df.columns if 'cat' in feature]
cont_features = [feature for feature in train_df.columns if 'cont' in feature]

train_df.describe().T

train_df.drop('id', axis=1, inplace=True)
test_df.drop('id', axis=1, inplace=True)

x = train_df.drop(['target'], axis=1)
y = train_df['target']
X_test = test_df.copy()

from sklearn.preprocessing import OrdinalEncoder
ordinal_encoder = OrdinalEncoder()
x[cat_features] = ordinal_encoder.fit_transform(x[cat_features])
X_test[cat_features] = ordinal_encoder.transform(X_test[cat_features])
x.head()