Kaggle competition: Expedia Hotel Recommendations
<SOS> metric: MAP@{K} Kaggle data source: expedia-hotel-recommendations<train_model>
sns.set_style('whitegrid')
 %matplotlib inline
optR = OptimizedRounder()
optR.fit(valid_preds[0],valid_preds[1] )<load_from_csv>
expedia_df = pd.read_csv('.. /input/train.csv', nrows=10000)
 test_df = pd.read_csv('.. /input/test.csv')
 expedia_df.head()
sample_df = pd.read_csv(PATH/'sample_submission.csv')
 sample_df.head()<define_variables>
expedia_df = expedia_df.drop(['date_time','site_name', 'user_location_region', 'user_location_city', 'orig_destination_distance',
'user_id', 'srch_co', 'srch_adults_cnt', 'srch_children_cnt', 'srch_rm_cnt', 'cnt'], axis=1)
 test_df = test_df.drop(['date_time','site_name', 'user_location_region', 'user_location_city', 'orig_destination_distance',
'user_id', 'srch_co', 'srch_adults_cnt', 'srch_children_cnt', 'srch_rm_cnt'], axis=1 )
learn.data.add_test(ImageList.from_df(sample_df,PATH,folder='test_images',suffix='.png'))<predict_on_test>
train_df = pd.read_csv('.. /input/train.csv', usecols=['is_booking', 'srch_destination_id', 'hotel_cluster'])
 test_df = test_df[['id', 'srch_destination_id']]
preds,y = learn.get_preds(DatasetType.Test)
<predict_on_test>
train_df = train_df.groupby(['srch_destination_id','hotel_cluster'])['is_booking'].agg(['sum','count'])
 train_df['count'] = train_df['count'] - train_df['sum']
train_df.rename(columns={'sum': 'sum_bookings', 'count': 'clicks'}, inplace=True)
 train_df['relevance'] = train_df['sum_bookings'] +(train_df['clicks'] * 0.1 )
test_predictions = optR.predict(preds, coefficients )<data_type_conversions>
def get_top_clusters(group):
indexes = group.relevance.nlargest(5 ).index
top_clusters = group.hotel_cluster[indexes].values
if(len(top_clusters)< 5):
top_clusters =(list(top_clusters)+ list(ferq_clusters.index)) [:5]
return np.array_str(np.array(top_clusters)) [1:-1]
train_df = train_df.reset_index()
ferq_clusters = train_df['hotel_cluster'].value_counts() [:5]
top_clusters = train_df.groupby(['srch_destination_id'] ).apply(get_top_clusters )
sample_df.diagnosis = test_predictions.astype(int)
 sample_df.head()<save_to_csv>
top_clusters_df = pd.DataFrame(top_clusters ).rename(columns={0: 'hotel_cluster'})
 top_clusters_df.head()
sample_df.to_csv('submission.csv',index=False )<set_options>
test_df = pd.merge(test_df, top_clusters_df, how='left',left_on='srch_destination_id', right_index=True)
 test_df.hotel_cluster.fillna(np.array_str(ferq_clusters.index)[1:-1],inplace=True)
 Y_pred = test_df["hotel_cluster"]
%matplotlib inline
warnings.filterwarnings("ignore" )<load_from_csv>
submission = pd.DataFrame()
submission["id"] = test_df["id"]
submission["hotel_cluster"] = Y_pred
submission.to_csv('expedia.csv', index=False )
data_dir = '.. /input/aptos2019-blindness-detection/'
test_dir = data_dir + '/test_images/'
label = pd.read_csv(data_dir+"test.csv")
 IMG_SIZE = 224<define_variables>