Kaggle competition: National Data Science Challenge 2019 - Advanced
<SOS> metric: map@{k} Kaggle data source: national-data-science-challenge-2019-advanced<feature_engineering>
from pathlib import Path
import json
import re
import sys
import warnings
import pickle
import pandas as pd
import numpy as np
from tqdm import tqdm_notebook
def add_day(df):
df['Date'] = df.index
df['Dayofyear'] = df['Date'].dt.dayofyear
return df<drop_column>
dl_df = pd.read_csv('.. /input/aoeul-solution-step-2-deep-learning-model/Deep_Learning_predictions.csv')
 svc_df = pd.read_csv('.. /input/aoeul-solution-step-1-linearsvc/LinearSVC_predictions.csv' )
confirmedT, deathsT, recoveredT, mortalityT = add_day(confirmedT), add_day(deathsT), add_day(recoveredT), add_day(mortalityT )<sort_values>
dl_df.head(10 )
allcountries_ordered = confirmed.set_index(['Country_Region'] ).iloc[:,-2].sort_values(ascending=False ).index.tolist()<save_to_csv>
svc_df.head(10 )
confirmed.set_index(['Country_Region'] ).iloc[:,-2].sort_values(ascending=False ).to_csv('confirmed_countries.csv' )<feature_engineering>
new_df = pd.merge(dl_df, svc_df, on='id')
 new_df.head()
def df_day1(df, confirmed):
df_day1 = pd.DataFrame({'Days since 100 cases' : np.arange(1000)} ).set_index('Days since 100 cases')
 countries_df = df.columns.tolist() [:-2]
countries_conf = confirmed.columns.tolist() [:-2]
for ic, country in enumerate(countries_df):
for ic2, country2 in enumerate(countries_conf):
if country == country2:
dfsub = df[confirmed[country] > 100.][country]
df_day1[country] = np.nan
df_day1.loc[:len(dfsub)-1,country] =(dfsub ).tolist()
df_day1 = df_day1.dropna(how='all')
 return df_day1<define_variables>
new_tag = []
i = 0
for _, row in tqdm_notebook(new_df.iterrows()):
x1, x2 = row.tagging_x.split(' ')
 x1 = int(x1)
 x2 = int(x2)
 y = row.tagging_y
if x1 == y:
new_tag.append(row.tagging_x)
 i = i + 1
else:
new_tag.append(str(y)+ ' '+ str(x1))
confirmed_day1 = df_day1(confirmedT, confirmedT)
 deaths_day1 = df_day1(deathsT, confirmedT)
 recovered_day1 = df_day1(recoveredT, confirmedT)
 mortality_day1 = df_day1(mortalityT, confirmedT)
 confirmednorm_day1 = confirmed_day1/confirmed_day1.loc[0,:]
maxday = confirmed_day1.shape[0]<data_type_conversions>
i/len(new_df)*100
<compute_train_metric><EOS> 
new_df['tagging']= np.array(new_tag)
 new_df = new_df[['id', 'tagging']]
new_df.to_csv(f'Ensembled_SVC_DL_predictions.csv', index=None )