Kaggle competition: Google Landmark Recognition Challenge
<SOS> metric: GoogleGlobalAP Kaggle data source: landmark-recognition-challenge<concatenate>
%matplotlib inline
models.append(model )<define_variables>
train_df = pd.read_csv('.. /input/train.csv')
 test_df = pd.read_csv('.. /input/test.csv')
 submission = pd.read_csv('.. /input/sample_submission.csv' )
test_predictions = []<predict_on_test>
missing = train_df.isnull().sum()
all_val = train_df.count()
missing_train_df = pd.concat([missing, all_val], axis=1, keys=['Missing', 'All'])
 missing_train_df
for model in models:
test_predictions.append(model.predict(test_inputs, batch_size=8))<prepare_output>
missing = test_df.isnull().sum()
all_val = test_df.count()
missing_test_df = pd.concat([missing, all_val], axis=1, keys=['Missing', 'All'])
 missing_test_df
final_predictions = np.mean(test_predictions, axis=0 )<save_to_csv>
train_df.nunique()
df_sub.iloc[:, 1:] = final_predictions
df_sub.to_csv('submission.csv', index=False )<import_modules>
test_df.nunique()
pyLDAvis.enable_notebook()
warnings.filterwarnings('ignore' )<load_from_csv>
concatenated = pd.concat([train_df, test_df])
 concatenated.shape
sample = pd.read_csv('/kaggle/input/google-quest-challenge/sample_submission.csv')
 sample.head(3 )<load_from_csv>
concatenated.nunique()
train = pd.read_csv('/kaggle/input/google-quest-challenge/train.csv')
 train.head(3 )<load_from_csv>
th10 = pd.DataFrame(train_df.landmark_id.value_counts().head(10))
th10.reset_index(level=0, inplace=True)
 th10.columns = ['landmark_id','count']
th10
test = pd.read_csv('/kaggle/input/google-quest-challenge/test.csv')
 test.head(3 )<define_variables>
tb10 = pd.DataFrame(train_df.landmark_id.value_counts().tail(10))
tb10.reset_index(level=0, inplace=True)
 tb10.columns = ['landmark_id','count']
tb10
targets = [
'question_asker_intent_understanding',
'question_body_critical',
'question_conversational',
'question_expect_short_answer',
'question_fact_seeking',
'question_has_commonly_accepted_answer',
'question_interestingness_others',
'question_interestingness_self',
'question_multi_intent',
'question_not_really_a_question',
'question_opinion_seeking',
'question_type_choice',
'question_type_compare',
'question_type_consequence',
'question_type_definition',
'question_type_entity',
'question_type_instructions',
'question_type_procedure',
'question_type_reason_explanation',
'question_type_spelling',
'question_well_written',
'answer_helpful',
'answer_level_of_information',
'answer_plausible',
'answer_relevance',
'answer_satisfaction',
'answer_type_instructions',
'answer_type_procedure',
'answer_type_reason_explanation',
'answer_well_written'
] 
<feature_engineering>
ll = list()
for path in train_df['url']:
ll.append(( path.split('//', 1)[1] ).split('/', 1)[0])
 train_df['site'] = ll
ll = list()
for path in test_df['url']:
ll.append(( path.split('//', 1)[1] ).split('/', 1)[0])
 test_df['site'] = ll
stopwords=stopwords.words('english')
 train['que_stopwords']=train['question_body'].apply(lambda x : [x for x in x.split() if x in stopwords])
 train['ans_stopwords']=train['answer'].apply(lambda x: [x for x in x.split() if x in stopwords] )<count_unique_values>
train_site = pd.DataFrame(train_df.site.value_counts())
 test_site = pd.DataFrame(test_df.site.value_counts() )
<set_options><EOS> 
freq_label = train_df['landmark_id'].value_counts() /train_df['landmark_id'].value_counts().sum()
submission['landmarks'] = '%d %2.2f' %(freq_label.index[0], freq_label.values[0])
 submission.to_csv('submission.csv', index=False)
 np.random.seed(2018)
 r_idx = lambda : np.random.choice(freq_label.index, p = freq_label.values)
 r_score = lambda idx: '%d %2.4f' %(freq_label.index[idx], freq_label.values[idx])
 submission['landmarks'] = submission.id.map(lambda _: r_score(r_idx()))
submission.to_csv('rand_submission.csv', index=False )