text_html_output_1.png
from sklearn.model_selection import train_test_split

from sklearn.preprocessing import LabelEncoder

import gc

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

data = pd.read_csv('../input/train.csv')
y = data.deal_probability.copy()
X_train, X_test, y_train, y_test = train_test_split(data, y, test_size=0.2, random_state=23)
del data
gc.collect()

predictors = ['num_desc_punct', 'num_words_title', 'words_vs_unique_title', 'num_unique_words_title', 'words_vs_unique_description', 'num_unique_words_description', 'num_words_description', 'price', 'item_seq_number', 'Day of Month', 'weekday']
categorical = ['image_top_1', 'param_1', 'param_2', 'param_3', 'city', 'region', 'category_name', 'parent_category_name', 'user_type']
predictors = predictors + categorical

for feature in categorical:
    print(f'Transforming {feature}...')
    encoder = LabelEncoder()
    X_train[feature].fillna('unknown', inplace=True)
    X_test[feature].fillna('unknown', inplace=True)
    encoder.fit(X_train[feature].append(X_test[feature]).astype(str))
    X_train[feature] = encoder.transform(X_train[feature].astype(str))
    X_test[feature] = encoder.transform(X_test[feature].astype(str))