def submission_with_postprocess(y_pred):
    df_sub = pd.read_csv('../input/petfinder-adoption-prediction/test/sample_submission.csv')
    train = pd.read_csv('../input/petfinder-adoption-prediction/train/train.csv')
    df_sub['AdoptionSpeed'] = y_pred
    duplicated = find_duplicates_all()
    duplicated = pd.DataFrame(duplicated, index=range(0)).T.reset_index()
    duplicated.columns = ['pet_id_0', 'pet_id_1']
    duplicated_0 = duplicated.merge(train[['PetID', 'AdoptionSpeed']], how='left', left_on='pet_id_0', right_on='PetID').dropna()
    df_sub = df_sub.merge(duplicated_0[['pet_id_1', 'AdoptionSpeed']], how='left', left_on='PetID', right_on='pet_id_1', suffixes=('_original', ''))
    df_sub['AdoptionSpeed'].fillna(df_sub['AdoptionSpeed_original'], inplace=True)
    df_sub = df_sub[['PetID', 'AdoptionSpeed']]
    duplicated_1 = duplicated.merge(train[['PetID', 'AdoptionSpeed']], how='left', left_on='pet_id_1', right_on='PetID').dropna()
    df_sub = df_sub.merge(duplicated_1[['pet_id_0', 'AdoptionSpeed']], how='left', left_on='PetID', right_on='pet_id_0', suffixes=('_original', ''))
    df_sub['AdoptionSpeed'].fillna(df_sub['AdoptionSpeed_original'], inplace=True)
    df_sub = df_sub[['PetID', 'AdoptionSpeed']]
    df_sub['AdoptionSpeed'] = df_sub['AdoptionSpeed'].astype('int32')
    df_sub.to_csv('submission.csv', index=False)
def submission_with_postprocess(y_pred):
    df_sub = pd.read_csv('../input/petfinder-adoption-prediction/test/sample_submission.csv')
    train = pd.read_csv('../input/petfinder-adoption-prediction/train/train.csv')
    df_sub['AdoptionSpeed'] = y_pred
    duplicated = find_duplicates_all()
    duplicated = pd.DataFrame(duplicated, index=range(0)).T.reset_index()
    duplicated.columns = ['pet_id_0', 'pet_id_1']
    duplicated_0 = duplicated.merge(train[['PetID', 'AdoptionSpeed']], how='left', left_on='pet_id_0', right_on='PetID').dropna()
    df_sub = df_sub.merge(duplicated_0[['pet_id_1', 'AdoptionSpeed']], how='left', left_on='PetID', right_on='pet_id_1', suffixes=('_original', ))
    df_sub['AdoptionSpeed'].fillna(df_sub['AdoptionSpeed_original'], inplace=True)
    df_sub = df_sub[['PetID', 'AdoptionSpeed']]
    duplicated_1 = duplicated.merge(train[['PetID', 'AdoptionSpeed']], how='left', left_on='pet_id_1', right_on='PetID').dropna()
    df_sub = df_sub.merge(duplicated_1[['pet_id_0', 'AdoptionSpeed']], how='left', left_on='PetID', right_on='pet_id_0', suffixes=('_original', ))
    df_sub['AdoptionSpeed'].fillna(df_sub['AdoptionSpeed_original'], inplace=True)
    df_sub = df_sub[['PetID', 'AdoptionSpeed']]
    df_sub['AdoptionSpeed'] = df_sub['AdoptionSpeed'].astype('int32')
    df_sub.to_csv('submission.csv', index=False)