Kaggle competition: Categorical Feature Encoding Challenge II
import os ; os.environ['OMP_NUM_THREADS'] = '4'<import_modules>
print(h2o.__version__)
 h2o.init(max_mem_size='16G' )
import pandas as pd
import operator
import matplotlib.pyplot as plt
import numpy as np
import nltk
import time<load_from_csv>
%%time
train = h2o.import_file(".. /input/multi-cat-encodings/X_train_te.csv")
 test = h2o.import_file(".. /input/multi-cat-encodings/X_test_te.csv" )
df = pd.read_csv('.. /input/train.tsv', sep='\t')
 df_sub = pd.read_csv('.. /input/test.tsv', sep='\t')
 submission = pd.DataFrame()
submission['test_id'] = df_sub.test_id.copy()
y_target = list(df.price )<count_missing_values>
x = test.columns
y = 'target'
train[y] = train[y].asfactor()
def null_percentage(column):
df_name = column.name
nans = np.count_nonzero(column.isnull().values)
 total = column.size
frac = nans / total
perc = int(frac * 100)
 print('%d%% or %d missing from %s column.' % 
(perc, nans, df_name))
def check_null(df, columns):
for col in columns:
null_percentage(df[col])
 check_null(df, df.columns)
<feature_engineering>
aml = H2OAutoML(seed=47, max_runtime_secs=30000)
 aml.train(x=x, y=y, training_frame=train, fold_column='fold_column' )
def merc_imputer(df_temp):
df_temp.brand_name = df_temp.brand_name.replace(np.nan, 'no_brand')
 df_temp.category_name = df_temp.category_name.replace(np.nan, 'uncategorized/uncategorized')
 df_temp.item_description = df_temp.item_description.replace(np.nan, 'No description yet')
 df_temp.item_description = df_temp.item_description.replace('No description yet', 'no_description')
 return df_temp
df = merc_imputer(df)
 df_sub = merc_imputer(df_sub )<train_model>
aml.leader
print('Training Data')
 check_null(df, df.columns)
 print('Submission Data')
 check_null(df_sub, df_sub.columns )<count_values>
preds = aml.predict(test)
 preds['p1'].as_data_frame().values.flatten().shape
df.shipping.value_counts()<count_values>
sample_submission = pd.read_csv('.. /input/cat-in-the-dat-ii/sample_submission.csv')
 sample_submission.shape
<filter><EOS> 
sample_submission['target'] = preds['p1'].as_data_frame().values
sample_submission.to_csv('h2o_automl_submission_4.csv', index=False )