Kaggle competition: Toxic Comment Classification Challenge
train_times = 3
n_folds = 5
i = 0
metrics_all = np.zeros(( train_times, 2))
for seed_varying in range(train_times):
print('
=======================================================')
 print('The ', seed_varying, ' time of train')
 print('
=======================================================')
 sub, fi, metrics = train_with_cv(train, test, n_folds, seed_varying)
 if i==0:
submission = sub
feat_
else:
submission['TARGET'] += sub['TARGET']
feat_import['importance'] += fi['importance']
metrics_all[i, :] = metrics.iloc[-1, 1:3]
i += 1
metrics_all_average = metrics_all.mean(axis = 0)
 metrics_all = np.row_stack([metrics_all, metrics_all_average])
 train_time_names = list(range(train_times))
train_time_names.append('Average')
 metrics_final = pd.DataFrame({'train_time': train_time_names,
'train': metrics_all[:,0],
'valid': metrics_all[:,1]})
 submission['TARGET'] = submission['TARGET'] / train_times
feat_import['importance'] = feat_import['importance'] / train_times
submission.to_csv('lightgbm_version_9.csv', index = False )<import_modules>
f_lstm_glove = '.. /input/improved-lstm-baseline-glove-dropout/submission.csv'
f_nbsvm = '.. /input/nb-svm-strong-linear-baseline/submission.csv'
f_lstm_fast = '.. /input/improved-lstm-baseline-fasttext-dropout/submission.csv'
f_bi_gru_dual = '.. /input/improved-lstm-baseline-bi-gru-dual-embedding/submission.csv'
init_notebook_mode(connected=True )<load_from_csv>
p_lstm_glove = pd.read_csv(f_lstm_glove)
 p_nbsvm = pd.read_csv(f_nbsvm)
 p_lstm_fast = pd.read_csv(f_lstm_fast)
 p_bi_gru_dual = pd.read_csv(f_bi_gru_dual )
print("Loading data files...")
 start = time()
posc_bal = reduce_mem_usage(pd.read_csv(".. /input/POS_CASH_balance.csv"))
bureau_bal = reduce_mem_usage(pd.read_csv(".. /input/bureau_balance.csv"))
app_train = reduce_mem_usage(pd.read_csv(".. /input/application_train.csv"))
prev_app = reduce_mem_usage(pd.read_csv(".. /input/previous_application.csv"))
inst_pay = reduce_mem_usage(pd.read_csv(".. /input/installments_payments.csv"))
cc_bal = reduce_mem_usage(pd.read_csv(".. /input/credit_card_balance.csv"))
app_test = reduce_mem_usage(pd.read_csv(".. /input/application_test.csv"))
bureau = reduce_mem_usage(pd.read_csv(".. /input/bureau.csv"))
end = time()
print("Finished loading data files and running memory optimization in {} seconds.".format(int(round(end - start))))<count_missing_values>
label_cols = ['toxic', 'severe_toxic', 'obscene', 'threat', 'insult', 'identity_hate']
p_res = p_lstm_glove.copy()
p_res[label_cols] =(p_nbsvm[label_cols] + p_lstm_glove[label_cols] + p_lstm_fast[label_cols] + p_bi_gru_dual[label_cols])/ 4
eda = pd.DataFrame(
 [
['Point of Sale Cash Balance', posc_bal.shape[0], posc_bal.shape[1] - 2, np.sum(posc_bal.dtypes=='category'),
np.sum(posc_bal.isnull().sum() > 0), posc_bal.isnull().sum().sum() ],
['Bureau Balance', bureau_bal.shape[0], bureau_bal.shape[1] - 1, np.sum(bureau_bal.dtypes=='category'),
np.sum(bureau_bal.isnull().sum() > 0), bureau_bal.isnull().sum().sum() ],
['Applications Train', app_train.shape[0], app_train.shape[1] - 2, np.sum(app_train.dtypes=='category'),
np.sum(app_train.isnull().sum() > 0), app_train.isnull().sum().sum() ],
['Previous Applications', prev_app.shape[0], prev_app.shape[1] - 2, np.sum(prev_app.dtypes=='category'),
np.sum(prev_app.isnull().sum() > 0), prev_app.isnull().sum().sum() ],
['Installment Payments', inst_pay.shape[0], inst_pay.shape[1] - 2, np.sum(inst_pay.dtypes=='category'),
np.sum(inst_pay.isnull().sum() > 0), inst_pay.isnull().sum().sum() ],
['Credit Card Balance', cc_bal.shape[0], cc_bal.shape[1] - 2, np.sum(cc_bal.dtypes=='category'),
np.sum(cc_bal.isnull().sum() > 0), cc_bal.isnull().sum().sum() ],
['Applications Test', app_test.shape[0], app_test.shape[1] - 1, np.sum(app_test.dtypes=='category'),
np.sum(app_test.isnull().sum() > 0), app_test.isnull().sum().sum() ],
['Bureau', bureau.shape[0], bureau.shape[1] - 2, np.sum(bureau.dtypes=='category'),
np.sum(bureau.isnull().sum() > 0), bureau.isnull().sum().sum() ],
],
columns=['Dataset', 'samples', 'number_features', 'number_categorical_features', 'number_features_missing_values',
'total_number_missing_values'] 
)
 display(eda.head(8))<train_model>
p_res.to_csv('submission.csv', index=False )