Kaggle competition: Toxic Comment Classification Challenge
import pandas as pd
import numpy as np
import xgboost as xgb
from xgboost import plot_importance
from sklearn import svm, neighbors
from collections import Counter
from imblearn.over_sampling import SMOTE
from sklearn.model_selection import train_test_split
from sklearn.ensemble import VotingClassifier, RandomForestClassifier
import matplotlib.pyplot as plt<load_from_csv>
glove_submission = pd.read_csv(".. /input/bi-gru-cnn-poolings-gpu-kernel-version/submission.csv")
 fasttext_submission = pd.read_csv(".. /input/bi-gru-lstm-cnn-poolings-fasttext/submission.csv" )
data = pd.read_csv('.. /input/train.csv',dtype={'duration': int})
 data_test = pd.read_csv('.. /input/test.csv',dtype={'duration': int})
 subs = pd.read_csv('.. /input/sample_submission.csv',dtype={'duration': int})
 data = data[data['parentesco1'] == 1]<prepare_x_and_y>
categories = ['toxic', 'severe_toxic', 'obscene', 'threat', 'insult', 'identity_hate']
data_x,data_y = datas_plit(data)
 test_data = datas_plit(data_test)
 def comb(arr,data_csv):
test = []
for type in arr:
test.append(data_csv[type])
 data_csv.drop([type], axis=1,inplace=True)
 array2 = np.array(test)
 max_p_row= array2.argmax(axis=0)
 return max_p_row
data_csv1 = data
norent=data_csv1[data_csv1['v2a1'].isnull() ]
print(norent.shape)
 own_house=norent[norent['tipovivi1']==1]['Id'].count()
installments=norent[norent['tipovivi2']==1]['Id'].count()
rented=norent[norent['tipovivi3']==1]['Id'].count()
Precarious=norent[norent['tipovivi4']==1]['Id'].count()
other= norent[norent['tipovivi5']==1]['Id'].count()
num_list=[own_house,installments,rented,Precarious,other]
name_list=['own_house','installments','rented','Precarious','other']
plt.bar(range(len(num_list)) ,num_list,tick_label=name_list)
 plt.show()
life_condition={'wall_material':['paredblolad','paredzocalo','paredpreb','pareddes','paredmad','paredzinc','paredfibras','paredother'],
'elimbasu':['elimbasu1','elimbasu2','elimbasu3','elimbasu4','elimbasu5','elimbasu6'],
'floor':['pisomoscer','pisocemento','pisoother','pisonatur','pisonotiene','pisomadera'],
'roof':['techozinc','techoentrepiso','techocane','techootro'],
'water':['abastaguadentro','abastaguafuera','abastaguano'],
'electricity':['public','planpri','noelec','coopele'],
'sanitario':['sanitario1','sanitario2','sanitario3','sanitario5','sanitario6'],
'energcocinar':['energcocinar1','energcocinar2','energcocinar3','energcocinar4'],
'epared':['epared1','epared2','epared3'],
'etecho':['etecho1','etecho2','etecho3'],
'eviv':['eviv1','eviv2','eviv3'],
'sex':['male','female'],
'estadocivil':['estadocivil1','estadocivil2','estadocivil3','estadocivil4','estadocivil5','estadocivil6','estadocivil7'],
'parentesco':['parentesco1','parentesco2','parentesco3','parentesco4','parentesco5','parentesco6','parentesco7','parentesco8','parentesco9','parentesco10','parentesco11','parentesco12'],
'instlevel':['instlevel1', 'instlevel2', 'instlevel3', 'instlevel4', 'instlevel5', 'instlevel6', 'instlevel7', 'instlevel8', 'instlevel9'],
'tipovivi':['tipovivi1','tipovivi2','tipovivi3','tipovivi4','tipovivi5'],
'lugar':['lugar1','lugar2','lugar3','lugar4','lugar5','lugar6'],
'area':['area1',"area2"],
}
for life in(life_condition):
_type = comb(life_condition[life], data_x)
 data_x.insert(2,life, _type)
 for life in(life_condition):
_type = comb(life_condition[life], test_data)
 test_data.insert(2,life, _type)
 kind = ['regular', 'borderline1', 'borderline2', 'svm']
sm = SMOTE(kind='svm')
 X_res, y_res = sm.fit_sample(data_x, data_y)
 columns = test_data.columns.values
X_res = pd.DataFrame(X_res,columns=columns)
 print(X_res)
 print(test_data )<choose_model_class>
blend = fasttext_submission.copy()
blend[categories] =(0.5*fasttext_submission[categories].values +
0.5*glove_submission[categories].values)
 blend.head()
<predict_on_test><EOS> 
blend.to_csv("blend.csv", index=False )