Kaggle competition: Expedia Hotel Recommendations
tfms = get_transforms(do_flip=True, flip_vert=True, max_rotate=0.10, max_zoom=1.3, max_warp=0.0, max_lighting=0.2 )<normalization>
data =(
 src.transform(tfms,size=128)
.databunch() 
.normalize(imagenet_stats)
)
 data<compute_train_metric>
train = pd.read_csv('.. /input/train.csv',
dtype={'is_booking':bool,'srch_destination_id':np.int32, 'hotel_cluster':np.int32},
usecols=['srch_destination_id','is_booking','hotel_cluster'],
chunksize=1000000)
 aggs = []
print('-'*38)
 for chunk in train:
agg = chunk.groupby(['srch_destination_id',
'hotel_cluster'])['is_booking'].agg(['sum','count'])
 agg.reset_index(inplace=True)
 aggs.append(agg)
 print('.',end='')
 print('')
 aggs = pd.concat(aggs, axis=0)
 aggs.head()
def quadratic_kappa(y_hat, y):
return torch.tensor(cohen_kappa_score(torch.round(y_hat), y, weights='quadratic'),device='cuda:0')
 learn = cnn_learner(data, base_arch=models.resnet50 ,metrics=[quadratic_kappa],model_dir='/kaggle',pretrained=True )<find_best_params>
def most_popular(group, n_max=5):
relevance = group['relevance'].values
hotel_cluster = group['hotel_cluster'].values
most_popular = hotel_cluster[np.argsort(relevance)[::-1]][:n_max]
return np.array_str(most_popular)[1:-1]
learn.lr_find()
learn.recorder.plot()<train_model>
most_pop = agg.groupby(['srch_destination_id'] ).apply(most_popular)
 most_pop = pd.DataFrame(most_pop ).rename(columns={0:'hotel_cluster'})
 most_pop.head()
lr = 1e-2
learn.fit_one_cycle(3, lr )<normalization>
test = pd.read_csv('.. /input/test.csv',
dtype={'srch_destination_id':np.int32},
usecols=['srch_destination_id'], )
learn.data = data =(
 src.transform(tfms,size=224)
.databunch() 
.normalize(imagenet_stats)
)
 learn.lr_find()
learn.recorder.plot()<train_model>
test = test.merge(most_pop, how='left',left_on='srch_destination_id',right_index=True)
 test.head()
lr = 1e-2
learn.fit_one_cycle(5, lr )<find_best_params>
test.hotel_cluster.isnull().sum()
learn.unfreeze()
learn.lr_find()
learn.recorder.plot()<train_model>
most_pop_all = agg.groupby('hotel_cluster')['relevance'].sum().nlargest(5 ).index
most_pop_all = np.array_str(most_pop_all)[1:-1]
most_pop_all
learn.fit_one_cycle(5, slice(1e-6,1e-3))<predict_on_test>
test.hotel_cluster.fillna(most_pop_all,inplace=True )
<compute_test_metric><EOS> 
test.hotel_cluster.to_csv('predicted_with_pandas.csv',header=True, index_label='id' )