[~] Refactor

This commit is contained in:
Siarhei Siniak 2021-07-15 09:49:15 +03:00
parent 10553c739c
commit e60b290a00

@ -136,19 +136,6 @@ def kernel_2():
# %% [code] # %% [code]
train['comment_text'].apply(lambda x:len(str(x).split())).max() train['comment_text'].apply(lambda x:len(str(x).split())).max()
# %% [markdown]
# Writing a function for getting auc score for validation
# %% [code]
def roc_auc(predictions,target):
'''
This methods returns the AUC Score when given the Predictions
and Labels
'''
fpr, tpr, thresholds = metrics.roc_curve(target, predictions)
roc_auc = metrics.auc(fpr, tpr)
return roc_auc
# %% [markdown] # %% [markdown]
# ### Data Preparation # ### Data Preparation
@ -231,16 +218,64 @@ def kernel_2():
model.summary() model.summary()
# %% [code] return dict(
model.fit(xtrain_pad, ytrain, nb_epoch=5, batch_size=64*strategy.num_replicas_in_sync) #Multiplying by Strategy to run on TPU's model=model,
xtrain_pad=xtrain_pad,
ytrain=ytrain,
strategy=strategy,
xvalid_pad=xvalid_pad,
yvalid=yvalid,
xtrain_seq=xtrain_seq,
)
def kernel_3(
o_2,
):
# %% [markdown]
# Writing a function for getting auc score for validation
# %% [code] # %% [code]
scores = model.predict(xvalid_pad) def roc_auc(predictions,target):
print("Auc: %.2f%%" % (roc_auc(scores,yvalid))) '''
This methods returns the AUC Score when given the Predictions
and Labels
'''
fpr, tpr, thresholds = metrics.roc_curve(target, predictions)
roc_auc = metrics.auc(fpr, tpr)
return roc_auc
# %% [code]
o_2['model'].fit(
o_2['xtrain_pad'],
o_2['ytrain'],
nb_epoch=5,
batch_size=64*o_2['strategy'].num_replicas_in_sync
) #Multiplying by Strategy to run on TPU's
# %% [code]
scores = o_2['model'].predict(o_2['xvalid_pad'])
print(
"Auc: %.2f%%" % (
roc_auc(
scores,
o_2['yvalid']
)
)
)
# %% [code] # %% [code]
scores_model = [] scores_model = []
scores_model.append({'Model': 'SimpleRNN','AUC_Score': roc_auc(scores,yvalid)}) scores_model.append(
{
'Model': 'SimpleRNN',
'AUC_Score': roc_auc(
scores,
o_2['yvalid']
)
}
)
# %% [markdown] # %% [markdown]
# ## Code Explanantion # ## Code Explanantion