Kaggle competition: Quora Insincere Questions Classification
final_test['IsMinor']=np.where(final_test['Age']<=16, 1, 0 )<prepare_x_and_y>
train_df = pd.read_csv(".. /input/train.csv")
 test_df = pd.read_csv(".. /input/test.csv")
 print("Train shape : ",train_df.shape)
 print("Test shape : ",test_df.shape )
cols=["Age", "Fare", "TravelAlone", "Pclass_1", "Pclass_2","Embarked_C","Embarked_S","Sex_male","IsMinor"]
X=df_final[cols]
Y=df_final['Survived']<train_model>
%%time
train_df, val_df = train_test_split(train_df, test_size=0.1, random_state=2018)
 embed_size = 300
max_features = 100000
maxlen = 70
train_X = train_df["question_text"].fillna("_na_" ).values
val_X = val_df["question_text"].fillna("_na_" ).values
test_X = test_df["question_text"].fillna("_na_" ).values
tokenizer = Tokenizer(num_words=max_features)
 tokenizer.fit_on_texts(list(train_X))
train_X = tokenizer.texts_to_sequences(train_X)
 val_X = tokenizer.texts_to_sequences(val_X)
 test_X = tokenizer.texts_to_sequences(test_X)
 train_X = pad_sequences(train_X, maxlen=maxlen)
 val_X = pad_sequences(val_X, maxlen=maxlen)
 test_X = pad_sequences(test_X, maxlen=maxlen)
 train_y = train_df['target'].values
val_y = val_df['target'].values
cols2=["Age", "Pclass_1", "Pclass_2","Embarked_C","Embarked_S","Sex_male"]
X2=df_final[cols2]
Y=df_final['Survived']
logit_model=sm.Logit(Y,X2)
 result=logit_model.fit()
sys.stdout.write(GREEN)
 print(result.summary() )<train_model>
model.fit(train_X, train_y, batch_size=512, epochs=3, validation_data=(val_X, val_y))
logreg = LogisticRegression()
logreg.fit(X2, Y)
 print("Model Accuracy : {:.2f}%".format(logreg.score(X2, Y)*100))<split>
pred_noemb_val_y = model.predict([val_X], batch_size=1024, verbose=1)[:,0]
train, test = train_test_split(df_final, test_size=0.25 )<train_model>
thresh = 0.50
pred_noemb_val_y_int = pred_noemb_val_y > thresh
print('ค่า accuracy เท่ากับ %.4f' %(sum(pred_noemb_val_y_int == val_y)/len(val_y)))
 print('ค่า F1 เท่ากับ %.4f' %(metrics.f1_score(val_y,(pred_noemb_val_y>thresh ).astype(int))))
cols2=["Age", "Pclass_1", "Pclass_2","Embarked_C","Embarked_S","Sex_male"]
X3=train[cols2]
Y3=train['Survived']
logit_model3=sm.Logit(Y3,X3 )<train_model>
count = np.logical_and(pred_noemb_val_y_int == val_y, val_y == 1)
 print('ค่า precision : %4f '%(sum(count)/sum(pred_noemb_val_y_int == 1)))
 print('ค่า recall : %4f '%(sum(count)/sum(val_y == 1)) )
logreg = LogisticRegression()
logreg.fit(X3, Y3)
 sys.stdout.write(GREEN)
 print("Model Accuracy : {:.2f}%".format(logreg.score(X3, Y3)*100))<train_model>
idx_1 = np.where(val_y == 1)[0]
print(pred_noemb_val_y[idx_1[:10]])
 print(val_y[idx_1[:10]] )
logreg.fit(X3, Y3)
 X3_test = test[cols2]
Y3_test = test['Survived']
Y3test_pred = logreg.predict(X3_test)
 sys.stdout.write(GREEN)
 print('Accuracy of logistic regression classifier on test set: {:.2f}'.format(logreg.score(X3_test, Y3_test)*100))<compute_train_metric>
best_thresh = 0.2
max_f1 = 0
for thresh in np.arange(0.2, 0.601, 0.01):
thresh = np.round(thresh, 2)
 current_f1 = metrics.f1_score(val_y,(pred_noemb_val_y>thresh ).astype(int))
print("ค่า F1 ที่ threshold %.2f is %.4f" %(thresh, current_f1))
if current_f1 > max_f1:
best_thresh = thresh
max_f1 = current_f1
print('ค่า threshold ที่ดีที่สุดคือ %.2f ให้ค่า F1 เท่ากับ %.4f' %(best_thresh,max_f1))
logreg.fit(X3, Y3)
 Y3_pred = logreg.predict(X3)
 y_true = Y3
y_scores = Y3_pred
sys.stdout.write(GREEN)
 print("Model ROC_AUC : {:.2f}%".format(roc_auc_score(y_true, y_scores)) )<train_model>
pred_noemb_test_y = model.predict([test_X], batch_size=1024, verbose=1 )
cols=["Age", "Fare", "TravelAlone", "Pclass_1", "Pclass_2","Embarked_C","Embarked_S","Sex_male","IsMinor"]
X=df_final[cols]
Y=df_final['Survived']
random_forest = RandomForestClassifier(n_estimators=100)
 random_forest.fit(X, Y)
 sys.stdout.write(GREEN)
 print('ROC AUC: %0.3f' % random_forest.score(X, Y))<predict_on_test>
del model, inp, x
time.sleep(10 )
final_test_RF=final_test[cols]
Y_pred_RF = random_forest.predict(final_test_RF )<save_to_csv>

 def load_glove_fast(word_index, max_words=max_features, embed_size=300):
EMBEDDING_FILE = '.. /input/embeddings/glove.840B.300d/glove.840B.300d.txt'
emb_mean, emb_std = -0.005838499, 0.48782197
embedding_matrix = np.random.normal(emb_mean, emb_std,(max_words, embed_size))
with open(EMBEDDING_FILE, 'r', encoding="utf8")as f:
for line in f:
word, vec = line.split(' ', 1)
 if word not in word_index:
continue
i = word_index[word]
if i >= max_words:
continue
embedding_vector = np.asarray(vec.split(' '), dtype='float32')[:300]
if len(embedding_vector)== 300:
embedding_matrix[i] = embedding_vector
return embedding_matrix
def load_fasttext_fast(word_index, max_words=max_features, embed_size=300):
EMBEDDING_FILE = '.. /input/embeddings/wiki-news-300d-1M/wiki-news-300d-1M.vec'
emb_mean, emb_std = -0.0033470048, 0.109855264
embedding_matrix = np.random.normal(emb_mean, emb_std,(max_words, embed_size))
with open(EMBEDDING_FILE, 'r', encoding="utf8")as f:
for line in f:
if len(line)<= 100:
continue
word, vec = line.split(' ', 1)
 if word not in word_index:
continue
i = word_index[word]
if i >= max_words:
continue
embedding_vector = np.asarray(vec.split(' '), dtype='float32')[:300]
if len(embedding_vector)== 300:
embedding_matrix[i] = embedding_vector
return embedding_matrix
def load_para_fast(word_index, max_words=max_features, embed_size=300):
EMBEDDING_FILE = '.. /input/embeddings/paragram_300_sl999/paragram_300_sl999.txt'
emb_mean, emb_std = -0.0053247833, 0.49346462
embedding_matrix = np.random.normal(emb_mean, emb_std,(max_words, embed_size))
with open(EMBEDDING_FILE, 'r', encoding="utf8", errors="ignore")as f:
for line in f:
if len(line)<= 100:
continue
word, vec = line.split(' ', 1)
 if word not in word_index:
continue
i = word_index[word]
if i >= max_words:
continue
embedding_vector = np.asarray(vec.split(' '), dtype='float32')[:300]
if len(embedding_vector)== 300:
embedding_matrix[i] = embedding_vector
return embedding_matrix
submission = pd.DataFrame({
"PassengerId": test_df["PassengerId"],
"Survived": Y_pred_RF
})
 submission.to_csv('titanic_RF.csv', index=False )<choose_model_class>
%%time

 embedding_matrix = load_glove_fast(tokenizer.word_index)
tree1 = tree.DecisionTreeClassifier(criterion='gini', splitter='best',max_depth=3, min_samples_leaf=20 )<prepare_x_and_y>

 inp = Input(shape=(maxlen,))
x = Embedding(max_features, embed_size, weights=[embedding_matrix] )(inp)
 x = Bidirectional(CuDNNGRU(64, return_sequences=True))(x)
 x = GlobalMaxPool1D()(x)
 x = Dense(16, activation="relu" )(x)
 x = Dropout(0.1 )(x)
 x = Dense(1, activation="sigmoid" )(x)
 model = Model(inputs=inp, outputs=x)
 model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
 print(model.summary() )
cols=["Age", "Fare", "TravelAlone", "Pclass_1", "Pclass_2","Embarked_C","Embarked_S","Sex_male","IsMinor"]
X_DT=df_final[cols]
Y_DT=df_final['Survived']
tree1.fit(X_DT, Y_DT )<save_to_csv>
model.fit(train_X, train_y, batch_size=512, epochs=3, validation_data=(val_X, val_y))
tree1_view = tree.export_graphviz(tree1, out_file=None, feature_names = X_DT.columns.values, rotate=True)
 tree1viz = graphviz.Source(tree1_view)
 tree1viz<save_to_csv>
pred_glove_val_y = model.predict([val_X], batch_size=1024, verbose=1)
final_test_DT=final_test[cols]
Y_pred_DT = tree1.predict(final_test_DT)
 submission = pd.DataFrame({
"PassengerId": test_df["PassengerId"],
"Survived": Y_pred_DT
})
 submission.to_csv('titanic_DT.csv', index=False )<save_to_csv>
best_thresh = 0.2
max_f1 = 0
for thresh in np.arange(0.2, 0.601, 0.01):
thresh = np.round(thresh, 2)
 current_f1 = metrics.f1_score(val_y,(pred_glove_val_y>thresh ).astype(int))
print("ค่า F1 ที่ threshold %.2f is %.4f" %(thresh, current_f1))
if current_f1 > max_f1:
best_thresh = thresh
max_f1 = current_f1
print('ค่า threshold ที่ดีที่สุดคือ %.2f ให้ค่า F1 เท่ากับ %.4f' %(best_thresh,max_f1))
submission = pd.DataFrame({
"PassengerId": test_df["PassengerId"],
"Survived": Y_pred_RF* 0.8 + Y_pred_DT*0.2
})
 submission.to_csv('titanic_ensemble.csv', index=False )<import_modules>

 pred_glove_test_y = model.predict([test_X], batch_size=1024, verbose=1 )
from sympy import simplify, cos, sin, Symbol, Function, tanh, pprint, init_printing, exp
from sympy.functions import Min,Max<prepare_x_and_y>

 del embedding_matrix, model, x
time.sleep(10 )
A = 0.058823499828577
B = 0.841127
C = 0.138462007045746
D = 0.31830988618379069
E = 2.810815
F = 0.63661977236758138
G = 5.428569793701172
H = 3.1415926535897931
I = 0.592158
J = 4.869778
K = 0.063467
L = -0.091481
M = 0.0821533
N = 0.720430016517639
O = 0.230145
P = 9.89287
Q = 785
R = 1.07241
S = 281
T = 734
U = 5.3
V = 67.0
W = 2.484848
X = 8.48635
Y = 63
Z = 12.6275
AA = 0.735354
AB = 727
AC = 2.5
AD = 2.6
AE = 0.3
AF = 3.0
AG = 0.226263
AH = 2.0
AI = 12.4148
AJ = 96
AK = 0.130303
AL = 176
AM = 3.2
BIG = [A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK,AL,AM]<compute_test_metric>
embedding_matrix = load_fasttext_fast(tokenizer.word_index)
 inp = Input(shape=(maxlen,))
x = Embedding(max_features, embed_size, weights=[embedding_matrix] )(inp)
 x = Bidirectional(CuDNNGRU(64, return_sequences=True))(x)
 x = GlobalMaxPool1D()(x)
 x = Dense(16, activation="relu" )(x)
 x = Dropout(0.1 )(x)
 x = Dense(1, activation="sigmoid" )(x)
 model = Model(inputs=inp, outputs=x)
 model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
 model.summary()
def GeneticFunction(data,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK,AL,AM):
return(( np.minimum(((((A + data["Sex"])- np.cos(( data["Pclass"] / AH)))* AH)) ,(( B)))* AH)+
np.maximum(((data["SibSp"] - AC)) ,(-(np.minimum(( data["Sex"]),(np.sin(data["Parch"])))* data["Pclass"])))+ 
(AG *(( np.minimum(( data["Sex"]),(((data["Parch"] / AH)/ AH)))* data["Age"])- data["Cabin"])) +
np.minimum(((np.sin(( data["Parch"] *(( data["Fare"] - AA)* AH)))* AH)) ,(( data["SibSp"] / AH)))+
np.maximum(( np.minimum(( -np.cos(data["Embarked"])) ,(C))),(np.sin(((data["Cabin"] - data["Fare"])* AH)))) +
-np.minimum(((((data["Age"] * data["Parch"])* data["Embarked"])+ data["Parch"])) ,(np.sin(data["Pclass"])))+
np.minimum(( data["Sex"]),(( np.sin(-(data["Fare"] * np.cos(( data["Fare"] * W)))) / AH)))+
np.minimum(((O)) ,(np.sin(np.minimum(((( V / AH)* np.sin(data["Fare"]))),(D)))))+
np.sin(( np.sin(data["Cabin"])*(np.sin(( Z)) * np.maximum(( data["Age"]),(data["Fare"])))))+
np.sin(((np.minimum(( data["Fare"]),(( data["Cabin"] * data["Embarked"])))/ AH)* -data["Fare"])) +
np.minimum(((( AD * data["SibSp"])* np.sin(((AJ)* np.sin(data["Cabin"]))))),(data["Parch"])) +
np.sin(np.sin(( np.maximum(( np.minimum(( data["Age"]),(data["Cabin"]))),(( data["Fare"] * AK)))* data["Cabin"])))+
np.maximum(( np.sin(((AI)*(data["Age"] / AH)))) ,(np.sin(( -AF * data["Cabin"])))) + 
(np.minimum(( np.sin(((( np.sin(((data["Fare"] * AH)* AH)) * AH)* AH)* AH))),(data["SibSp"])) / AH)+ 
(( data["Sex"] - data["SibSp"])*(np.cos(((data["Embarked"] - AA)+ data["Age"])) / AH)) + 
(( np.sin(data["Cabin"])/ AH)-(np.cos(np.minimum(( data["Age"]),(data["Embarked"])))* np.sin(data["Embarked"])))+
np.minimum(( AE),(( data["Sex"] *(J *(N - np.sin(( data["Age"] * AH)))))))+ 
(np.minimum(( np.cos(data["Fare"])) ,(np.maximum(( np.sin(data["Age"])) ,(data["Parch"])))) * np.cos(( data["Fare"] / AH)))+
np.sin(( data["Parch"] * np.minimum(((data["Age"] - K)) ,(( np.cos(( data["Pclass"] * AH)) / AH)))))+ 
(data["Parch"] *(np.sin(((data["Fare"] *(I * data["Age"])) * AH)) / AH)) + 
(D * np.cos(np.maximum(((0.5 * data["Fare"])) ,(( np.sin(N)* data["Age"])))))+ 
(np.minimum(((data["SibSp"] / AH)) ,(np.sin(((data["Pclass"] - data["Fare"])* data["SibSp"])))) * data["SibSp"])+
np.tanh(( data["Sex"] * np.sin(( U * np.sin(( data["Cabin"] * np.cos(data["Fare"])))))))+ 
(np.minimum(( data["Parch"]),(data["Sex"])) * np.cos(np.maximum(((np.cos(data["Parch"])+ data["Age"])) ,(AM)))) + 
(np.minimum(( np.tanh(((data["Cabin"] / AH)+ data["Parch"]))),(( data["Sex"] + np.cos(data["Age"])))) / AH)+ 
(np.sin(( np.sin(data["Sex"])*(np.sin(( data["Age"] * data["Pclass"])) * data["Pclass"])))/ AH)+ 
(data["Sex"] *(np.cos(((data["Sex"] + data["Fare"])*(( X)*(Y)))) / AH)) +
np.minimum(( data["Sex"]),(( np.cos(( data["Age"] * np.tanh(np.sin(np.cos(data["Fare"])))))/ AH)))+ 
(np.tanh(np.tanh(-np.cos(( np.maximum(( np.cos(data["Fare"])) ,(L)) * data["Age"])))) / AH)+ 
(np.tanh(np.cos(( np.cos(data["Age"])+(data["Age"] + np.minimum(( data["Fare"]),(data["Age"])))))) / AH)+ 
(np.tanh(np.cos(( data["Age"] *(( -AH + np.sin(data["SibSp"])) + data["Fare"])))) / AH)+ 
(np.minimum(((( S)- data["Fare"])) ,(np.sin(( np.maximum(((AL)) ,(data["Fare"])) * data["SibSp"])))) * AH)+
np.sin(((np.maximum(( data["Embarked"]),(data["Age"])) * AH)*(((Q)* H)* data["Age"])))+
np.minimum(( data["Sex"]),(np.sin(-(np.minimum(((data["Cabin"] / AH)) ,(data["SibSp"])) *(data["Fare"] / AH)))))+
np.sin(np.sin(( data["Cabin"] *(data["Embarked"] +(np.tanh(-data["Age"])+ data["Fare"])))))+ 
(np.cos(np.cos(data["Fare"])) *(np.sin(( data["Embarked"] -(( T)* data["Fare"])))/ AH)) + 
(( np.minimum(( data["SibSp"]),(np.cos(data["Fare"])))* np.cos(data["SibSp"])) * np.sin(( data["Age"] / AH)))+ 
(np.sin(( np.sin(( data["SibSp"] * np.cos(( data["Fare"] * AH)))) +(data["Cabin"] * AH)))/ AH)+ 
(((data["Sex"] * data["SibSp"])* np.sin(np.sin(-(data["Fare"] * data["Cabin"])))) * AH)+ 
(np.sin(( data["SibSp"] *(((( G + V)* AH)/ AH)* data["Age"])))/ AH)+ 
(data["Pclass"] *(np.sin(((data["Embarked"] * data["Cabin"])*(data["Age"] -(R)))) / AH)) + 
(np.cos(((((-data["SibSp"] + data["Age"])+ data["Parch"])* data["Embarked"])/ AH)) / AH)+ 
(D * np.sin(((data["Age"] *(( data["Embarked"] * np.sin(data["Fare"])) * AH)) * AH)))+ 
(( np.minimum(((data["Age"] * A)) ,(data["Sex"])) - F)* np.tanh(np.sin(data["Pclass"])))+
-np.minimum(((np.cos(((AB)*(( data["Fare"] + data["Parch"])* AH)))/ AH)) ,(data["Fare"])) + 
(np.minimum(( np.cos(data["Fare"])) ,(data["SibSp"])) * np.minimum(( np.sin(data["Parch"])) ,(np.cos(( data["Embarked"] * AH)))))+ 
(np.minimum(((( data["Fare"] / AH)- E)) ,(C)) * np.sin(( K * data["Age"])))+
np.minimum(((M)) ,(((np.sin(data["Fare"])+ data["Embarked"])- np.cos(( data["Age"] *(P)))))) )<feature_engineering>
model.fit(train_X, train_y, batch_size=512, epochs=3, validation_data=(val_X, val_y))
def CleanData(data):
data.drop(['Ticket', 'Name'], inplace=True, axis=1)
 data.Sex.fillna('0', inplace=True)
 data.loc[data.Sex != 'male', 'Sex'] = 0
data.loc[data.Sex == 'male', 'Sex'] = 1
data.Cabin.fillna('0', inplace=True)
 data.loc[data.Cabin.str[0] == 'A', 'Cabin'] = 1
data.loc[data.Cabin.str[0] == 'B', 'Cabin'] = 2
data.loc[data.Cabin.str[0] == 'C', 'Cabin'] = 3
data.loc[data.Cabin.str[0] == 'D', 'Cabin'] = 4
data.loc[data.Cabin.str[0] == 'E', 'Cabin'] = 5
data.loc[data.Cabin.str[0] == 'F', 'Cabin'] = 6
data.loc[data.Cabin.str[0] == 'G', 'Cabin'] = 7
data.loc[data.Cabin.str[0] == 'T', 'Cabin'] = 8
data.loc[data.Embarked == 'C', 'Embarked'] = 1
data.loc[data.Embarked == 'Q', 'Embarked'] = 2
data.loc[data.Embarked == 'S', 'Embarked'] = 3
data.Embarked.fillna(0, inplace=True)
 data.fillna(-1, inplace=True)
 return data.astype(float)
 def Outputs(data):
return np.round(1.-(1./(1.+np.exp(-data))))<load_from_csv>
pred_fasttext_val_y = model.predict([val_X], batch_size=1024, verbose=1)
 max_f1 = 0
for thresh in np.arange(0.2, 0.601, 0.01):
thresh = np.round(thresh, 2)
 current_f1 = metrics.f1_score(val_y,(pred_fasttext_val_y>thresh ).astype(int))
print("ค่า F1 ที่ threshold %.2f is %.4f" %(thresh, current_f1))
if current_f1 > max_f1:
best_thresh = thresh
max_f1 = current_f1
print('ค่า threshold ที่ดีที่สุดคือ %.2f ให้ค่า F1 เท่ากับ %.4f' %(best_thresh,max_f1))
raw_train = pd.read_csv('.. /input/titanic/train.csv')
 raw_test = pd.read_csv('.. /input/titanic/test.csv')
 cleanedTrain = CleanData(raw_train)
 cleanedTest = CleanData(raw_test)
 thisArray = BIG.copy()
testPredictions = Outputs(GeneticFunction(cleanedTrain,thisArray[0],thisArray[1],thisArray[2],thisArray[3],thisArray[4],thisArray[5],thisArray[6],thisArray[7],thisArray[8],thisArray[9],thisArray[10],thisArray[11],thisArray[12],thisArray[13],thisArray[14],thisArray[15],thisArray[16],thisArray[17],thisArray[18],thisArray[19],thisArray[20],thisArray[21],thisArray[22],thisArray[23],thisArray[24],thisArray[25],thisArray[26],thisArray[27],thisArray[28],thisArray[29],thisArray[30],thisArray[31],thisArray[32],thisArray[33],thisArray[34],thisArray[35],thisArray[36],thisArray[37],thisArray[38]))
pdcheck = pd.DataFrame({'Survived': testPredictions.astype(int)})
 ret = pdcheck.Survived.where(pdcheck["Survived"].values==cleanedTrain["Survived"].values ).notna()
t,f = ret.value_counts()
score = 100/(t+f)*t
print("Training set score: ",score )<save_to_csv>
pred_fasttext_test_y = model.predict([test_X], batch_size=1024, verbose=1 )
testPredictions = Outputs(GeneticFunction(cleanedTest,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK,AL,AM))
pdtest = pd.DataFrame({'PassengerId': cleanedTest.PassengerId.astype(int),
'Survived': testPredictions.astype(int)})
 pdtest.to_csv('submission_GA.csv', index=False)
 pdtest.head()<import_modules>

 del embedding_matrix, model, x
time.sleep(10 )
if not sys.warnoptions:
warnings.simplefilter("ignore")
<load_from_csv>
embedding_matrix = load_para_fast(tokenizer.word_index)
 inp = Input(shape=(maxlen,))
x = Embedding(max_features, embed_size, weights=[embedding_matrix] )(inp)
 x = Bidirectional(CuDNNGRU(64, return_sequences=True))(x)
 x = GlobalMaxPool1D()(x)
 x = Dense(16, activation="relu" )(x)
 x = Dropout(0.1 )(x)
 x = Dense(1, activation="sigmoid" )(x)
 model = Model(inputs=inp, outputs=x)
 model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
 model.summary()
data_train = pd.read_csv(".. /input/train.csv")
 data_test= pd.read_csv(".. /input/test.csv" )<train_model>
model.fit(train_X, train_y, batch_size=512, epochs=3, validation_data=(val_X, val_y))
print("Training Data shape:", data_train.shape)
 print("Test Data shape:", data_test.shape )<prepare_x_and_y>
pred_paragram_val_y = model.predict([val_X], batch_size=1024, verbose=1 )
label = data_train['Survived']<count_missing_values>
max_f1 = 0
for thresh in np.arange(0.2, 0.601, 0.01):
thresh = np.round(thresh, 2)
 current_f1 = metrics.f1_score(val_y,(pred_paragram_val_y>thresh ).astype(int))
print("ค่า F1 ที่ threshold %.2f is %.4f" %(thresh, current_f1))
if current_f1 > max_f1:
best_thresh = thresh
max_f1 = current_f1
print('ค่า threshold ที่ดีที่สุดคือ %.2f ให้ค่า F1 เท่ากับ %.4f' %(best_thresh,max_f1))
if label.isnull().sum() ==0:
print("No missing values")
 else:
print(label.isnull().sum() , 'missing values found in dataset' )<count_unique_values>
pred_paragram_test_y = model.predict([test_X], batch_size=1024, verbose=1 )
for column in data_train.columns:
print(column, len(data_train[column].unique()))<count_missing_values>

 del embedding_matrix, model, x
time.sleep(10 )
print('Amount of missing data in Fare for train:', data_train.Fare.isnull().sum())
 print('Amount of missing data in Fare for test:',data_test.Fare.isnull().sum())
 print("--------------------------------------------------")
 print('Amount of missing data in Embarked for train:',data_train.Embarked.isnull().sum())
 print('Amount of missing data in Embarked for test:', data_test.Embarked.isnull().sum() )<feature_engineering>

 pred_val_y = 0.33*pred_glove_val_y + 0.33*pred_fasttext_val_y + 0.34*pred_paragram_val_y
max_f1 = 0
for thresh in np.arange(0.2, 0.601, 0.01):
thresh = np.round(thresh, 2)
 current_f1 = metrics.f1_score(val_y,(pred_val_y>thresh ).astype(int))
print("ค่า F1 ที่ threshold %.2f is %.4f" %(thresh, current_f1))
if current_f1 > max_f1:
best_thresh = thresh
max_f1 = current_f1
print('ค่า threshold ที่ดีที่สุดคือ %.2f ให้ค่า F1 เท่ากับ %.4f' %(best_thresh,max_f1))
<count_missing_values><EOS> 
pred_test_y = 0.33*pred_glove_test_y + 0.33*pred_fasttext_test_y + 0.34*pred_paragram_test_y
pred_test_y =(pred_test_y>0.35 ).astype(int)
 out_df = pd.DataFrame({"qid":test_df["qid"].values})
 out_df['prediction'] = pred_test_y
out_df.to_csv("submission.csv", index=False )