Kaggle competition: Toxic Comment Classification Challenge
def ensamble_predict(models, x):
pred = np.zeros(( x.shape[0], 4))
for model in models:
pred +=(model.train(mode=False )(x ).cpu().data.numpy() / len(models))
return np.array([pred[r].argmax(axis=0)for r in range(len(pred)) ] )<compute_train_metric>
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'
f1_score(y_val.values, ensamble_predict(models, X_val), average='macro' )<predict_on_test>
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 )
targ = y_val.values
preds = ensamble_predict(models, X_val)
 conf_mat(targ, preds )<compute_train_metric>
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])/ 3
<compute_test_metric><EOS> 
p_res.to_csv('submission.csv', index=False )