Kaggle competition: COVID19 Global Forecasting (Week 4)
train_df = pd.read_csv(path/'train.csv')
 train_df.head()<load_from_csv>
submission=pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/submission.csv' )
test_df = pd.read_csv(path/'sample_submission.csv')
 print(test_df.shape)
 test_df.head()<load_pretrained>
submission=pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/submission.csv' )
tfms = get_transforms(do_flip=True, flip_vert=True, max_rotate=10.0, max_zoom=1.1, max_lighting=0.2, max_warp=0.2, p_affine=0.75, p_lighting=0.75)
 train_data = ImageDataBunch.from_df(path/'train'/'train', train_df, ds_tfms=tfms, size=128 )<define_variables>
submission = pd.read_csv(".. /input/covid19-global-forecasting-week-4/submission.csv")
 test = pd.read_csv(".. /input/covid19-global-forecasting-week-4/test.csv")
 train = pd.read_csv(".. /input/covid19-global-forecasting-week-4/train.csv")
 train.Province_State.fillna("None", inplace=True)
 display(train.head(5))
display(train.describe())
 print("Number of Country_Region: ", train['Country_Region'].nunique())
 print("Dates go from day", max(train['Date']), "to day", min(train['Date']), ", a total of", train['Date'].nunique() , "days")
 print("Countries with Province/State informed: ", train.loc[train['Province_State']!='None']['Country_Region'].unique() )
train_data.show_batch(rows=3, figsize=(5,6))<choose_model_class>
confirmed_total_date_Italy = train[train['Country_Region']=='Italy'].groupby(['Date'] ).agg({'ConfirmedCases':['sum']})
 fatalities_total_date_Italy = train[train['Country_Region']=='Italy'].groupby(['Date'] ).agg({'Fatalities':['sum']})
 total_date_Italy = confirmed_total_date_Italy.join(fatalities_total_date_Italy)
 confirmed_total_date_Spain = train[train['Country_Region']=='Spain'].groupby(['Date'] ).agg({'ConfirmedCases':['sum']})
 fatalities_total_date_Spain = train[train['Country_Region']=='Spain'].groupby(['Date'] ).agg({'Fatalities':['sum']})
 total_date_Spain = confirmed_total_date_Spain.join(fatalities_total_date_Spain)
 confirmed_total_date_UK = train[train['Country_Region']=='United Kingdom'].groupby(['Date'] ).agg({'ConfirmedCases':['sum']})
 fatalities_total_date_UK = train[train['Country_Region']=='United Kingdom'].groupby(['Date'] ).agg({'Fatalities':['sum']})
 total_date_UK = confirmed_total_date_UK.join(fatalities_total_date_UK)
 confirmed_total_date_Australia = train[train['Country_Region']=='Australia'].groupby(['Date'] ).agg({'ConfirmedCases':['sum']})
 fatalities_total_date_Australia = train[train['Country_Region']=='Australia'].groupby(['Date'] ).agg({'Fatalities':['sum']})
 total_date_Australia = confirmed_total_date_Australia.join(fatalities_total_date_Australia)
 confirmed_total_date_Singapore = train[train['Country_Region']=='Singapore'].groupby(['Date'] ).agg({'ConfirmedCases':['sum']})
 fatalities_total_date_Singapore = train[train['Country_Region']=='Singapore'].groupby(['Date'] ).agg({'Fatalities':['sum']})
 total_date_Singapore = confirmed_total_date_Singapore.join(fatalities_total_date_Singapore)
 confirmed_total_date_India = train[train['Country_Region']=='India'].groupby(['Date'] ).agg({'ConfirmedCases':['sum']})
 fatalities_total_date_India = train[train['Country_Region']=='India'].groupby(['Date'] ).agg({'Fatalities':['sum']})
 total_date_India = confirmed_total_date_India.join(fatalities_total_date_India)
 confirmed_total_date_US = train[train['Country_Region']=='US'].groupby(['Date'] ).agg({'ConfirmedCases':['sum']})
 fatalities_total_date_US = train[train['Country_Region']=='US'].groupby(['Date'] ).agg({'Fatalities':['sum']})
 total_date_US = confirmed_total_date_US.join(fatalities_total_date_US)
 plt.figure(figsize=(17,10))
plt.subplot(3, 2, 1)
 total_date_Italy.plot(ax=plt.gca() , title='Italy')
 plt.ylabel("Confirmed infection cases", size=13)
 plt.subplot(3, 2, 2)
 total_date_Spain.plot(ax=plt.gca() , title='Spain')
 plt.subplot(3, 2, 3)
 total_date_UK.plot(ax=plt.gca() , title='United Kingdom')
 plt.ylabel("Confirmed infection cases", size=13)
 plt.subplot(3, 2, 4)
 total_date_India.plot(ax=plt.gca() , title='India')
 plt.subplot(3, 2, 5)
 total_date_Australia.plot(ax=plt.gca() , title='Australia')
 plt.ylabel("Confirmed infection cases", size=13)
 plt.subplot(3, 2, 6)
 total_date_US.plot(ax=plt.gca() , title='United States')
 plt.ylabel("Confirmed infection cases", size=13 )
learn = cnn_learner(train_data, models.densenet161, metrics=[accuracy],model_dir="/tmp/model/" )<find_best_params>
pop_India=1377011281.
 pop_US=330578810.
 pop_spain = 46749696.
 pop_italy = 60486683.
 pop_UK = 67784927.
 pop_singapore = 5837230.
 total_date_India.ConfirmedCases = total_date_India.ConfirmedCases/pop_India*100.
 total_date_India.Fatalities = total_date_India.ConfirmedCases/pop_India*100.
 total_date_US.ConfirmedCases = total_date_US.ConfirmedCases/pop_US*100.
 total_date_US.Fatalities = total_date_US.ConfirmedCases/pop_US*100.
 total_date_Italy.ConfirmedCases = total_date_Italy.ConfirmedCases/pop_italy*100.
 total_date_Italy.Fatalities = total_date_Italy.ConfirmedCases/pop_italy*100.
 total_date_Spain.ConfirmedCases = total_date_Spain.ConfirmedCases/pop_spain*100.
 total_date_Spain.Fatalities = total_date_Spain.ConfirmedCases/pop_spain*100.
 total_date_UK.ConfirmedCases = total_date_UK.ConfirmedCases/pop_UK*100.
 total_date_UK.Fatalities = total_date_UK.ConfirmedCases/pop_UK*100.
 total_date_Singapore.ConfirmedCases = total_date_Singapore.ConfirmedCases/pop_singapore*100.
 total_date_Singapore.Fatalities = total_date_Singapore.ConfirmedCases/pop_singapore*100.
 plt.figure(figsize=(15,10))
plt.subplot(3, 2, 1)
 total_date_India.ConfirmedCases.plot(ax=plt.gca() , title='India')
 plt.ylabel("Fraction of population infected")
 plt.ylim(0, 0.05)
 plt.subplot(3, 2, 2)
 total_date_US.ConfirmedCases.plot(ax=plt.gca() , title='US')
 plt.ylim(0, 0.05)
 plt.subplot(3, 2, 3)
 total_date_Spain.ConfirmedCases.plot(ax=plt.gca() , title='Spain')
 plt.ylabel("Fraction of population infected")
 plt.ylim(0, 0.05)
 plt.subplot(3, 2, 4)
 total_date_Italy.ConfirmedCases.plot(ax=plt.gca() , title='Italy')
 plt.ylim(0, 0.05)
 plt.subplot(3, 2, 5)
 total_date_UK.ConfirmedCases.plot(ax=plt.gca() , title='United Kingdom')
 plt.ylabel("Fraction of population infected")
 plt.ylim(0, 0.05)
 plt.subplot(3, 2, 6)
 total_date_Singapore.ConfirmedCases.plot(ax=plt.gca() , title='Singapore')
 plt.ylim(0, 0.05 )
learn.lr_find()<train_model>
confirmed_total_date_India = train[(train['Country_Region']=='India')& train['ConfirmedCases']!=0].groupby(['Date'] ).agg({'ConfirmedCases':['sum']})
 fatalities_total_date_India = train[(train['Country_Region']=='India')& train['ConfirmedCases']!=0].groupby(['Date'] ).agg({'Fatalities':['sum']})
 total_date_India = confirmed_total_date_India.join(fatalities_total_date_India)
 confirmed_total_date_US = train[(train['Country_Region']=='US')& train['ConfirmedCases']!=0].groupby(['Date'] ).agg({'ConfirmedCases':['sum']})
 fatalities_total_date_US = train[(train['Country_Region']=='US')& train['ConfirmedCases']!=0].groupby(['Date'] ).agg({'Fatalities':['sum']})
 total_date_US = confirmed_total_date_US.join(fatalities_total_date_US)
 confirmed_total_date_Italy = train[(train['Country_Region']=='Italy')& train['ConfirmedCases']!=0].groupby(['Date'] ).agg({'ConfirmedCases':['sum']})
 fatalities_total_date_Italy = train[(train['Country_Region']=='Italy')& train['ConfirmedCases']!=0].groupby(['Date'] ).agg({'Fatalities':['sum']})
 total_date_Italy = confirmed_total_date_Italy.join(fatalities_total_date_Italy)
 confirmed_total_date_Spain = train[(train['Country_Region']=='Spain')&(train['ConfirmedCases']!=0)].groupby(['Date'] ).agg({'ConfirmedCases':['sum']})
 fatalities_total_date_Spain = train[(train['Country_Region']=='Spain')&(train['ConfirmedCases']!=0)].groupby(['Date'] ).agg({'Fatalities':['sum']})
 total_date_Spain = confirmed_total_date_Spain.join(fatalities_total_date_Spain)
 confirmed_total_date_UK = train[(train['Country_Region']=='United Kingdom')&(train['ConfirmedCases']!=0)].groupby(['Date'] ).agg({'ConfirmedCases':['sum']})
 fatalities_total_date_UK = train[(train['Country_Region']=='United Kingdom')&(train['ConfirmedCases']!=0)].groupby(['Date'] ).agg({'Fatalities':['sum']})
 total_date_UK = confirmed_total_date_UK.join(fatalities_total_date_UK)
 confirmed_total_date_Australia = train[(train['Country_Region']=='Australia')&(train['ConfirmedCases']!=0)].groupby(['Date'] ).agg({'ConfirmedCases':['sum']})
 fatalities_total_date_Australia = train[(train['Country_Region']=='Australia')&(train['ConfirmedCases']!=0)].groupby(['Date'] ).agg({'Fatalities':['sum']})
 total_date_Australia = confirmed_total_date_Australia.join(fatalities_total_date_Australia)
 confirmed_total_date_Singapore = train[(train['Country_Region']=='Singapore')&(train['ConfirmedCases']!=0)].groupby(['Date'] ).agg({'ConfirmedCases':['sum']})
 fatalities_total_date_Singapore = train[(train['Country_Region']=='Singapore')&(train['ConfirmedCases']!=0)].groupby(['Date'] ).agg({'Fatalities':['sum']})
 total_date_Singapore = confirmed_total_date_Singapore.join(fatalities_total_date_Singapore)
 India = [i for i in total_date_India.ConfirmedCases['sum'].values]
India_30 = India[0:70]
US = [i for i in total_date_US.ConfirmedCases['sum'].values]
US_30 = US[0:70]
italy = [i for i in total_date_Italy.ConfirmedCases['sum'].values]
italy_30 = italy[0:70]
spain = [i for i in total_date_Spain.ConfirmedCases['sum'].values]
spain_30 = spain[0:70]
UK = [i for i in total_date_UK.ConfirmedCases['sum'].values]
UK_30 = UK[0:70]
singapore = [i for i in total_date_Singapore.ConfirmedCases['sum'].values]
singapore_30 = singapore[0:70]
plt.figure(figsize=(12,6))
plt.plot(India_30)
 plt.plot(US_30)
 plt.plot(italy_30)
 plt.plot(spain_30)
 plt.plot(UK_30)
 plt.plot(singapore_30)
 plt.legend(["India","US", "Italy", "Spain", "UK", "Singapore"], loc='upper left')
 plt.title("COVID-19 infections from the first| confirmed case", size=15)
 plt.xlabel("Days", size=13)
 plt.ylabel("Infected cases", size=13)
 plt.ylim(0, 300000)
 plt.show()
lr =1.0e-2
learn.fit_one_cycle(7,slice(lr))<create_dataframe>
le = preprocessing.LabelEncoder()
solution = pd.DataFrame(columns=test_df.columns)
 solution<predict_on_test>
df = train.fillna('NA' ).groupby(['Country_Region','Province_State','Date'])['ConfirmedCases'].sum() \ 
.groupby(['Country_Region','Province_State'] ).max().sort_values() \ 
.groupby(['Country_Region'] ).sum().sort_values(ascending = False)
 top20_countries = pd.DataFrame(df ).head(20)
 top20_countries
for index,row in test_df.iterrows() :
img_name = row['id']
img = open_image(path/'test'/'test'/img_name)
 pred_class,pred_idx,outputs = learn.predict(img)
 solution.loc[len(solution)] = [img_name,outputs.numpy() [1]]<save_to_csv>
train['Date'] = pd.to_datetime(train['Date'], infer_datetime_format=True)
 test['Date'] = pd.to_datetime(test['Date'], infer_datetime_format=True )
solution.to_csv('submission.csv', index=False )<set_options>
train.loc[:, 'Date'] = train.Date.dt.strftime('%y%m%d')
 train.loc[:, 'Date'] = train['Date'].astype(int)
 test.loc[:, 'Date'] = test.Date.dt.strftime('%y%m%d')
 test.loc[:, 'Date'] = test['Date'].astype(int )
%matplotlib inline
seed = 42<load_from_csv>
train['Province_State'] = np.where(train['Province_State'] == 'nan',train['Country_Region'],train['Province_State'])
 test['Province_State'] = np.where(test['Province_State'] == 'nan',test['Country_Region'],test['Province_State'] )
train = pd.read_csv('.. /input/train.csv', nrows = 8000000, parse_dates = ['pickup_datetime'] )<correct_missing_values>
convert_dict = {'Province_State': str}
train = train.astype(convert_dict)
 test = test.astype(convert_dict )
train = train.dropna()<filter>
submission = pd.read_csv(".. /input/covid19-global-forecasting-week-4/submission.csv")
 test = pd.read_csv(".. /input/covid19-global-forecasting-week-4/test.csv")
 train = pd.read_csv(".. /input/covid19-global-forecasting-week-4/train.csv" )
train = train[select_within_boundingbox(train, BB)]<drop_column>
train.isna().sum()
train = train[train['fare_amount'].between(left = 2.50, right = 100)]
train = train.loc[train['passenger_count'] < 10]<feature_engineering>
test.isna().sum()
def transform_time(df):
df['year'] = df['pickup_datetime'].dt.year
df['month'] = df['pickup_datetime'].dt.month
df['day'] = df['pickup_datetime'].dt.day
df['hour'] = df['pickup_datetime'].dt.hour
df['minute'] = df['pickup_datetime'].dt.minute
df['second'] = df['pickup_datetime'].dt.second
df['weekday'] = df['pickup_datetime'].dt.weekday
df['PM'] =(df['hour'] >= 12 ).apply(int)
 df['dayofyear'] = df['pickup_datetime'].dt.dayofyear
df['daysinmonth'] = df['pickup_datetime'].dt.daysinmonth
df['is_leap_year'] =(df['pickup_datetime'].dt.is_leap_year ).apply(int)
 df['weekofyear'] = df['pickup_datetime'].dt.weekofyear
df['dayofweek'] = df['pickup_datetime'].dt.dayofweek
df['daysinyear'] = df['is_leap_year'].apply(lambda x : 366 if x == 1 else 365)
 df['frac_day'] =(df['hour'] +(df['minute'] / 60)+(df['second'] / 3600)) / 24
df['frac_week'] =(df['dayofweek'] + df['frac_day'])/ 7
df['frac_month'] =(df['day'] +(df['frac_day'])) /(df['daysinmonth'] + 1)
 df['frac_year'] =(df['dayofyear'] + df['frac_day'])/(df['daysinyear'] + 1)
 return df<compute_test_metric>
train['Province_State'].fillna("",inplace = True)
 test['Province_State'].fillna("",inplace = True )
def chebyshev(pickup_long, dropoff_long, pickup_lat, dropoff_lat):
return np.maximum(np.absolute(pickup_long - dropoff_long), np.absolute(pickup_lat - dropoff_lat))
def haversine(pickup_long, dropoff_long, pickup_lat, dropoff_lat):
dlon =(pickup_long - dropoff_long)* 0.0174533
dlat =(pickup_lat - dropoff_lat)* 0.0174533
lat1 = dropoff_lat
lat2 = pickup_lat
return 2.0 * 6371.0 * np.arcsin(np.power(np.power(np.sin(dlat/2.0),2)+ np.cos(lat1)* np.cos(lat2)* np.power(np.sin(dlon/2.0),2), 0.5))
def rotate_long(long, lat):
degree = 36.1
radian = degree * 0.0174533
return long * np.cos(radian)- lat * np.sin(radian)
 def rotate_lat(long, lat):
degree = 36.1
radian = degree * 0.0174533
return long * np.sin(radian)- lat * np.cos(radian )<feature_engineering>
train['Country_Region'] = train['Country_Region'] + ' ' + train['Province_State']
test['Country_Region'] = test['Country_Region'] + ' ' + test['Province_State']
del train['Province_State']
del test['Province_State']
def transform_distance(df):
df['abs_lat_diff'] =(df['dropoff_latitude'] - df['pickup_latitude'] ).abs()
df['abs_lon_diff'] =(df['dropoff_longitude'] - df['pickup_longitude'] ).abs()
df['Chebyshev'] = chebyshev(df['pickup_longitude'], df['dropoff_longitude'], df['pickup_latitude'], df['dropoff_latitude'])
 df['Haversine'] = haversine(df['pickup_longitude'], df['dropoff_longitude'], df['pickup_latitude'], df['dropoff_latitude'])
 nyc =(-74.0063889, 40.7141667)
 jfk =(-73.7822222222, 40.6441666667)
 ewr =(-74.175, 40.69)
 lgr =(-73.87, 40.77)
 df['cheb_nyc'] = chebyshev(nyc[0], df['dropoff_longitude'], nyc[1], df['dropoff_latitude'])
 df['cheb_jfk'] = chebyshev(jfk[0], df['dropoff_longitude'], jfk[1], df['dropoff_latitude'])
 df['cheb_ewr'] = chebyshev(ewr[0], df['dropoff_longitude'], ewr[1], df['dropoff_latitude'])
 df['cheb_lgr'] = chebyshev(lgr[0], df['dropoff_longitude'], lgr[1], df['dropoff_latitude'])
 df['hav_nyc'] = haversine(nyc[0], df['dropoff_longitude'], nyc[1], df['dropoff_latitude'])
 df['hav_jfk'] = haversine(jfk[0], df['dropoff_longitude'], jfk[1], df['dropoff_latitude'])
 df['hav_ewr'] = haversine(ewr[0], df['dropoff_longitude'], ewr[1], df['dropoff_latitude'])
 df['hav_lgr'] = haversine(lgr[0], df['dropoff_longitude'], lgr[1], df['dropoff_latitude'])
 df['rotate_pickup_longitude'] = rotate_long(df['pickup_longitude'], df['pickup_latitude'])
 df['rotate_pickup_latitude'] = rotate_lat(df['pickup_longitude'], df['pickup_latitude'])
 df['rotate_dropoff_longitude'] = rotate_long(df['dropoff_longitude'], df['dropoff_latitude'])
 df['rotate_dropoff_latitude'] = rotate_lat(df['dropoff_longitude'], df['dropoff_latitude'])
 return df<prepare_x_and_y>
def split_date(date):
date = date.split('-')
 date[0] = int(date[0])
 if(date[1][0] == '0'):
date[1] = int(date[1][1])
 else:
date[1] = int(date[1])
 if(date[2][0] == '0'):
date[2] = int(date[2][1])
 else:
date[2] = int(date[2])
 return date
train.Date = train.Date.apply(split_date)
 test.Date = test.Date.apply(split_date )
train = transform_time(train)
 train = transform_distance(train)
 train.drop(['pickup_datetime', 'key'], axis = 1, inplace = True)
 target = train.pop('fare_amount' )<split>
year = []
month = []
day = []
for i in train.Date:
year.append(i[0])
 month.append(i[1])
 day.append(i[2] )
X_train, X_val, y_train, y_val = train_test_split(train, target, test_size = 0.2, random_state = seed )<choose_model_class>
train['Year'] = year
train['Month'] = month
train['Day'] = day
del train['Date']
reg = xgb.XGBRegressor(eval_metric = 'rmse',
max_depth = 7,
subsample = 0.8,
learning_rate = 0.1,
gamma = 1,
colsample_bytree = 0.9,
random_state = seed,
n_jobs = -1 )<train_model>
year = []
month = []
day = []
for i in test.Date:
year.append(i[0])
 month.append(i[1])
 day.append(i[2] )
reg.fit(X_train, y_train )<compute_train_metric>
test['Year'] = year
test['Month'] = month
test['Day'] = day
del test['Date']
del train['Id']
del test['ForecastId']
train_pred = reg.predict(X_train)
 val_pred = reg.predict(X_val)
 rmse_train = np.sqrt(mean_squared_error(y_train, train_pred))
print('Training RMSE:', rmse_train)
 rmse_val = np.sqrt(mean_squared_error(y_val, val_pred))
print('Validation RMSE:', rmse_val )<load_from_csv>
del train['Year']
del test['Year']
test = pd.read_csv('.. /input/test.csv', parse_dates = ['pickup_datetime'])
 test = transform_time(test)
 test = transform_distance(test)
 test.drop(['pickup_datetime'], axis = 1, inplace = True)
 test_index = test.pop('key' )<predict_on_test>
train['ConfirmedCases'] = train['ConfirmedCases'].apply(int)
 train['Fatalities'] = train['Fatalities'].apply(int )
result = reg.predict(test )<save_to_csv>
cases = train.ConfirmedCases
fatalities = train.Fatalities
del train['ConfirmedCases']
del train['Fatalities']
submission = pd.DataFrame({
'key' : test_index,
'fare_amount' : result.flatten()
})
 submission.to_csv('solution.csv', index = False )<load_from_csv>
lb = LabelEncoder()
train['Country_Region'] = lb.fit_transform(train['Country_Region'])
 test['Country_Region'] = lb.transform(test['Country_Region'] )
s1=pd.read_csv('.. /input/s1v8-nanashi-90-lines-solution-0901-fast/s1-v8.csv')['target']
s2=pd.read_csv('.. /input/santander-magic-lgb-0-901/submission.csv')['target']
s3=pd.read_csv('.. /input/s3v32-ashish-gupta-eda-pca-scaler-lgbm/s3-v32.csv')['target']
s4=pd.read_csv('.. /input/eda-pca-simple-lgbm-on-kfold-technique/submission26.csv')['target']
s5=pd.read_csv('.. /input/lgb-2-leaves-augment/lgb_submission.csv')['target']
s6=pd.read_csv('.. /input/lightgbm-with-data-augmentation/2019-04-01_07_56_sub.csv')['target']
s7=pd.read_csv('.. /input/s7v19-subham-sharma-what-is-next-in-santander/s7-v19.csv')['target']
s8=pd.read_csv('.. /input/s8v5-joshua-reed-santander-customer-transaction/s8-v5.csv')['target']
s9=pd.read_csv('.. /input/s9v16-gauravtambi-lgbm-augmentation/s9-v16.csv')['target']
s10=pd.read_csv('.. /input/best-parameters-lb-0-900/submission.csv')['target']
submission = pd.read_csv('.. /input/santander-customer-transaction-prediction/sample_submission.csv')
 solutions_set = pd.DataFrame({'s1': s1, 's2': s2, 's3': s3, 's4': s4, 's5': s5, 's6': s6,
's7': s7, 's8': s8, 's9': s9, 's10': s10} )<normalization>
scaler = MinMaxScaler()
x_train = scaler.fit_transform(train.values)
 x_test = scaler.transform(test.values )
scaler = MinMaxScaler()
solutions_set_scaled = scaler.fit_transform(solutions_set)
 solutions_set_scaled = pd.DataFrame(solutions_set_scaled, columns = solutions_set.columns )<feature_engineering>
rf = XGBRegressor(n_estimators = 2500 , random_state = 0 , max_depth = 27)
 rf.fit(x_train,cases )
for s in solutions_set_scaled.columns:
s = solutions_set_scaled[s]
cluster1 = s7
cluster2 = 1/2*(s1 + s5 + s8 + s10)
 cluster3 = 1/4*(s2 + s3 + s4 + s6 + s9)
 submission['target'] = 0.1*cluster1 + 0.8*cluster2 + 0.1*cluster3<save_to_csv>
cases_pred = rf.predict(x_test)
 cases_pred
filename="blended_submission_{:%Y-%m-%d_%H_%M}.csv".format(datetime.now())
 submission.to_csv(filename, index=False )<set_options>
cases_pred = np.around(cases_pred,decimals = 0)
 cases_pred
%matplotlib inline 
<load_from_csv>
x_train_cas = []
for i in range(len(x_train)) :
x = list(x_train[i])
 x.append(cases[i])
 x_train_cas.append(x)
 x_train_cas[0]
santander_data = pd.read_csv('.. /input/train.csv')
 santander_data_test = pd.read_csv('.. /input/test.csv')
 santander_submission = pd.read_csv('.. /input/sample_submission.csv')
 print('Training df shape',santander_data.shape)
 print('Test df shape',santander_data_test.shape )<define_variables>
x_train_cas = np.array(x_train_cas )
label_df = santander_data['target']<drop_column>
rf = XGBRegressor(n_estimators = 2500 , random_state = 0 , max_depth = 27)
 rf.fit(x_train_cas,fatalities )
santander_data.drop(['ID_code','target'], axis=1, inplace=True)
 santander_data_test.drop('ID_code', axis=1, inplace=True)
 santander_data.head(5 )<define_variables>
x_test_cas = []
for i in range(len(x_test)) :
x = list(x_test[i])
 x.append(cases_pred[i])
 x_test_cas.append(x)
 x_test_cas[0]
len_train = len(santander_data)
 len_train<concatenate>
fatalities_pred = rf.predict(x_test_cas)
 fatalities_pred
merged = pd.concat([santander_data, santander_data_test] )<feature_engineering>
fatalities_pred = np.around(fatalities_pred,decimals = 0)
 fatalities_pred
idx = features = merged.columns.values[0:200]
for df in [merged]:
df['sum'] = df[idx].sum(axis=1)
 df['min'] = df[idx].min(axis=1)
 df['max'] = df[idx].max(axis=1)
 df['mean'] = df[idx].mean(axis=1)
 df['std'] = df[idx].std(axis=1)
 df['skew'] = df[idx].skew(axis=1)
 df['kurt'] = df[idx].kurtosis(axis=1)
 df['med'] = df[idx].median(axis=1 )<prepare_x_and_y>
submission['ConfirmedCases'] = cases_pred
submission['Fatalities'] = fatalities_pred
train_df = santander_data
X_test = santander_data_test
del santander_data
del santander_data_test
gc.collect()<choose_model_class>
submission.to_csv('submission.csv', index=False )
<init_hyperparams><EOS> 
submission.to_csv('submission.csv', index=False )