Kaggle competition: Tabular Playground Series - Jan 2021
<SOS> metric: RMSE Kaggle data source: tabular-playground-series-jan-2021<train_model>
sns.set(font_scale=1.4)
 def pl(nr=1, nc=1,fs1=20,fs2=7):
fig,axes=plt.subplots(nrows=nr, ncols=nc, figsize=(fs1, fs2))
return fig, axes
learn.fit_one_cycle(5, slice(1e-5, lr/5))<save_model>
PATH = '/kaggle/input/tabular-playground-series-jan-2021/'
train = pd.read_csv(PATH+'train.csv')
 test = pd.read_csv(PATH+'test.csv')
 sample_submission = pd.read_csv(PATH+'sample_submission.csv')
 FT_COLS = [x for x in train.columns if 'cont' in x]
LABEL='target'
learn.save('stage-2-256-rn50',return_path=True )<define_variables>
train['outlier_filter'] = np.where(train[LABEL]<4, True, False)
 print('
ol_filt = ~train['outlier_filter']
test = ImageList.from_folder(path/'test-jpg-v2' ).add(ImageList.from_folder(path/'test-jpg-additional'))
len(test )<predict_on_test>
NSUBS=4
SUBMISSION_DESCR = ['LGBM','XGB','KERAS','KERAS FEWER FTS',]
colors=['Blue','Green','Red', 'Pink',]
SUBMISSION_PATHS = ['/kaggle/input/jan21-lgbm-submission/',
'/kaggle/input/jan21-tabular-xgb-sub/',
'/kaggle/input/jan21-tabplayground-nn1-output/',
'/kaggle/input/jan21-tabplayground-nn2-output/',
]
learn = load_learner('.. /working/', test=test)
 preds, _ = learn.get_preds(ds_type=DatasetType.Test )<define_variables>
weights_range = [0.001 , 0.05, 0.1 , 0.15, 0.2 , 0.25, 0.3 , 0.35, 0.4 , 0.45, 0.5 ,
0.55, 0.6 , 0.65, 0.7 , 0.75, 0.8 , 0.85, 0.9 , 0.95, 0.999]
thresh = 0.2
labelled_preds = [' '.join([learn.data.classes[i] for i,p in enumerate(pred)if p > thresh])for pred in preds]<define_variables>
%%time
output_wts = np.zeros(( 194481,NSUBS+1))
j=0
for a,b,c,d in itertools.product(weights_range, repeat=NSUBS):
sum_w = np.array([a,b,c,d] ).sum()
wts = np.array([a,b,c,d])/ sum_w
final_oof_preds = np.zeros(( len(train),))
for count, w in enumerate(oof_list):
final_oof_preds+=oof_list[count] * wts[count]
output_wts[j,NSUBS] = np.sqrt(mse(train[LABEL], final_oof_preds))
output_wts[j,0:NSUBS] = wts
j+=1
fnames = [f.name[:-4] for f in learn.data.test_ds.items]<create_dataframe>
output_wts = output_wts.sort_values('oof_error' ).reset_index(drop=True)
 output_wts.head(10 )
df = pd.DataFrame({'image_name':fnames, 'tags':labelled_preds}, columns=['image_name', 'tags'] )<save_to_csv>
final_test_preds = np.zeros(( len(sample_submission),))
final_oof_preds = np.zeros(( len(train),))
for count, s in enumerate(submission_list):
final_test_preds+=submission_list[count] * selected_wts.values[count]
final_oof_preds+=oof_list[count] * selected_wts[count]
print('final CV error', np.sqrt(mse(train[LABEL], final_oof_preds)) )
df.to_csv('.. /working/submission.csv', index=False )<set_options>
sample_submission['target'] = final_test_preds
sample_submission.to_csv('submission.csv', index=False)
 sample_submission.head(5 )