[~] Refactor
This commit is contained in:
parent
10553c739c
commit
e60b290a00
@ -136,19 +136,6 @@ def kernel_2():
|
||||
# %% [code]
|
||||
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]
|
||||
# ### Data Preparation
|
||||
@ -231,16 +218,64 @@ def kernel_2():
|
||||
|
||||
model.summary()
|
||||
|
||||
# %% [code]
|
||||
model.fit(xtrain_pad, ytrain, nb_epoch=5, batch_size=64*strategy.num_replicas_in_sync) #Multiplying by Strategy to run on TPU's
|
||||
return dict(
|
||||
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]
|
||||
scores = model.predict(xvalid_pad)
|
||||
print("Auc: %.2f%%" % (roc_auc(scores,yvalid)))
|
||||
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
|
||||
|
||||
# %% [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]
|
||||
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]
|
||||
# ## Code Explanantion
|
||||
|
Loading…
Reference in New Issue
Block a user