Kaggle competition: Santander Value Prediction Challenge
<SOS> metric: RMSLE Kaggle data source: santander-value-prediction-challenge<categorify>
def rmse(y_true, y_pred):
return mean_squared_error(y_true, y_pred)**.5
test = pd.read_csv('.. /input/santander-value-prediction-challenge/test.csv')
 tst_leak = pd.read_csv('.. /input/santander-public-outputs/test_leak_37.csv')
 test['leak'] = tst_leak['compiled_leak']
merge_files = ['137','138_1','138_2','138_3','138_4','138_5']
weights = [3,1,1,1,1,1]
input_ids_train, attention_mask_train, token_type_ids_train = encode(train['cleaned_text'])
 input_ids_test, attention_mask_test, token_type_ids_test = encode(test['cleaned_text'] )<prepare_x_and_y>
score = pd.read_csv('.. /input/santander-value-prediction-challenge/sample_submission.csv', usecols=['ID'])
 for i in range(len(merge_files)) :
score_temp = pd.read_csv('.. /input/santander-public-outputs/'+ merge_files[i] +'.csv' ).rename(columns={'target':'score_'+ str(i)})
 score = pd.merge(score, score_temp, how='left', on='ID')
 score.head()
y= train['target']
y=np.array(y)
 del train
del test
del real_df
del not_realdf
del df_misl
del df
gc.collect()<prepare_x_and_y>
sum_pred = np.zeros(len(score), dtype=float)
 for i in range(len(merge_files)) :
sum_pred = sum_pred + list(score['score_'+str(i)].values*weights[i])
 avg_pred = sum_pred/sum(weights )
class ClassificationReport(Callback):
def __init__(self,train_data=() ,validation_data=()):
super(Callback,self ).__init__()
self.input_ids_train,self.attention_mask_train,self.token_type_ids_train,self.y_train = train_data
self.train_precision_scores =[]
self.train_recall_scores =[]
self.train_f1_scores=[]
self.input_ids_val, self.attention_mask_val, self.token_type_ids_val,self.y_val = validation_data
self.val_precision_scores =[]
self.val_recall_scores =[]
self.val_f1_scores =[]
def on_epoch_end(self,epoch, logs={}):
train_predictions = np.round(self.model.predict([self.input_ids_train,self.attention_mask_train,self.token_type_ids_train],verbose =0))
train_precision = precision_score(self.y_train, train_predictions, average='macro')
 train_recall = recall_score(self.y_train, train_predictions, average='macro')
 train_f1 = f1_score(self.y_train, train_predictions, average='macro')
 self.train_precision_scores.append(train_precision)
 self.train_recall_scores.append(train_recall)
 self.train_f1_scores.append(train_f1)
 val_predictions = np.round(self.model.predict([self.input_ids_val, self.attention_mask_val, self.token_type_ids_val], verbose=0))
val_precision = precision_score(self.y_val, val_predictions, average='macro')
 val_recall = recall_score(self.y_val, val_predictions, average='macro')
 val_f1 = f1_score(self.y_val, val_predictions, average='macro')
 self.val_precision_scores.append(val_precision)
 self.val_recall_scores.append(val_recall)
 self.val_f1_scores.append(val_f1)
 print('
Epoch: {} - Training Precision: {:.6} - Training Recall: {:.6} - Training F1: {:.6}'.format(epoch + 1, train_precision, train_recall, train_f1))
print('Epoch: {} - Validation Precision: {:.6} - Validation Recall: {:.6} - Validation F1: {:.6}'.format(epoch + 1, val_precision, val_recall, val_f1)) 
<choose_model_class>
filesave = "Blend_Finale"
lgsub = pd.DataFrame(avg_pred,columns=["target"])
 lgsub['ID'] = score['ID'].values
lgsub['leak'] = tst_leak['compiled_leak']
lgsub.loc[lgsub.leak.notnull() ,'target'] = lgsub.loc[lgsub.leak.notnull() , 'leak']
lgsub[['ID','target']].to_csv(filesave+".csv",index=False,header=True)
 lgsub[['ID','target']].head()