Kaggle competition: Tabular Playground Series - Jan 2021
<SOS> metric: RMSE Kaggle data source: tabular-playground-series-jan-2021<create_dataframe>
%matplotlib inline
dfk = pd.DataFrame({
'Kernel ID': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'],
'Score': [ 0.69864 , 0.69846 , 0.69836 , 0.69824 , 0.69813, 0.69795, 0.69751, 0.69749, 0.69747, 0.69735, 0.69731, 0.69701],
'File Path': ['.. /input/aa69864/AA69864.csv', '.. /input/bb69846/BB69846.csv', '.. /input/cc69836/CC69836.csv', '.. /input/a69824/A69824.csv', '.. /input/c69813/C69813.csv', '.. /input/ff69795/FF69795.csv', '.. /input/gg69751/GG69751.csv' , '.. /input/g69749/G69749.csv', '.. /input/h69747/H69747.csv', '.. /input/i69735/I69735.csv', '.. /input/j69731/J69731.csv', '.. /input/l69701/L69701.csv']
})
 dfk
print('Getting test_ids')
 IMG_SIZE = 500
NUM_TEST_IMAGES = count_data_items(files_test_500)
 ds_test = get_dataset(files_test_500,augment=False,repeat=False,shuffle=False,
dim=IMG_SIZE,batch_size=BATCH_SIZE*4)
 test_ids_ds = ds_test.map(lambda image, idnum: idnum ).unbatch()
test_ids = next(iter(test_ids_ds.batch(NUM_TEST_IMAGES)) ).numpy().astype('U')
<define_variables>
def generate(main, support, coeff):
g = main.copy()
for i in main.columns[1:]:
res = []
lm, Is = [], []
lm = main[i].tolist()
ls = support[i].tolist()
for j in range(len(main)) :
res.append(( lm[j] * coeff)+(ls[j] *(1.- coeff)))
 g[i] = res
return g
tta_counter = 0<define_variables>
support = pd.read_csv(dfk.iloc[0, 2])
 for k in range(1, 7):
main = pd.read_csv(dfk.iloc[k, 2])
 support = generate(main, support, 0.99)
 sub1 = support
VERBOSE = IS_INTERACTIVE
def generate_submission(EFF_NET,category,TTA):
if EFF_NET == RESNEXT_ID:
model_root = f'.. /input/cassava-category-{category}/ResNext50/ResNext50/'
else:
model_root = f'.. /input/cassava-category-{category}/B{EFF_NET}/B{EFF_NET}/'
if category%2==0:
IMG_SIZE = 600
files_test = files_test_600
elif category%2==1:
IMG_SIZE = 500
files_test = files_test_500
else:
assert 1==2, "INVALID CATEGORY"
global tta_counter
test_predictions = []
for fold in range(FOLDS):
print('
if EFF_NET == RESNEXT_ID:
print(' 
(IMG_SIZE,BATCH_SIZE*REPLICAS))
else:
print(' 
(IMG_SIZE,EFF_NET,BATCH_SIZE*REPLICAS))
K.clear_session()
with strategy.scope() :
model = build_model(dim=IMG_SIZE,ef=EFF_NET)
 print('Loading best model...')
 model.load_weights(model_root+'fold-%i.h5'%fold)
 if len(TTA)==0:
print('Predicting TEST without TTA...')
 ds_test = get_dataset(files_test,augment=False,repeat=False,shuffle=False,
dim=IMG_SIZE,batch_size=BATCH_SIZE)
 pred = model.predict(ds_test,verbose=VERBOSE,batch_size=BATCH_SIZE,
use_multiprocessing=True,workers=N_WORKERS)
 if 1:
print('Predicting TEST with TTA...')
 for x_ in range(1):
tta = TTA[tta_counter%8]
print(tta)
 tta_counter+=1
ds_test = get_dataset(files_test,augment=False,tta=tta,repeat=False,shuffle=False,
dim=IMG_SIZE,batch_size=BATCH_SIZE)
 if x_==0:
pred = model.predict(ds_test,verbose=VERBOSE,batch_size=BATCH_SIZE,
use_multiprocessing=True,workers=N_WORKERS)/len(TTA)
 else:
pred += model.predict(ds_test,verbose=VERBOSE,batch_size=BATCH_SIZE,
use_multiprocessing=True,workers=N_WORKERS)/len(TTA)
 test_pred_fold = pd.DataFrame(pred)
 test_pred_fold['fold'] = fold
test_pred_fold['image_id'] = test_ids
test_predictions.append(test_pred_fold)
 test_predictions = pd.concat(test_predictions)
 test_predictions_averaged = test_predictions.groupby('image_id')[[0,1,2,3,4]].mean()
test_predictions_averaged = test_predictions_averaged.sort_index()
return test_predictions_averaged<define_variables>
sub7 = comparison(sub6, 7, 1.0036, 0.9972)
<prepare_output><EOS> 
sub = sub7
sub.to_csv("submission.csv", index=False)
 sub1.to_csv("submission1.csv", index=False)
 sub2.to_csv("submission2.csv", index=False)
 sub3.to_csv("submission3.csv", index=False)
 sub4.to_csv("submission4.csv", index=False)
 sub5.to_csv("submission5.csv", index=False)
 sub6.to_csv("submission6.csv", index=False)
 !ls