Kaggle competition: COVID19 Global Forecasting (Week 3)
sub.columns = ['ForecastId', 'ConfirmedCases', 'Fatalities']<feature_engineering>
plt.style.use('ggplot')
 font = {'family' : 'meiryo'}
plt.rc('font', **font )
sub.loc[sub['ConfirmedCases']<0, 'ConfirmedCases'] = 0<feature_engineering>
train_df = pd.read_csv(".. /input/covid19-global-forecasting-week-3/train.csv" )
sub.loc[sub['Fatalities']<0, 'Fatalities'] = 0<drop_column>
train_df = train_df[train_df["Date"] < "2020-03-27"]
train_df = train_df.fillna("No State" )
<load_from_csv>
test_rate = 0.05
maxlen = 13
train_date_count = len(set(train_df["Date"]))
X, Y = [],[]
scaler = StandardScaler()
train_df["ConfirmedCases_std"] = scaler.fit_transform(train_df["ConfirmedCases"].values.reshape(len(train_df["ConfirmedCases"].values),1))
confirmedCase_std_min = train_df["ConfirmedCases_std"].min()
train_df["ConfirmedCases_std"] = train_df["ConfirmedCases_std"] + abs(confirmedCase_std_min)
 for state,country in train_df.groupby(["Province_State","Country_Region"] ).sum().index:
df = train_df[(train_df["Country_Region"] == country)&(train_df["Province_State"] == state)]
if df["ConfirmedCases"].sum() != 0:
for i in range(len(df)- maxlen):
X.append(df[['ConfirmedCases_std']].iloc[i:(i+maxlen)].values)
 Y.append(df[['ConfirmedCases_std']].iloc[i+maxlen].values)
 X=np.array(X)
 Y=np.array(Y)
 X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=test_rate, shuffle = True ,random_state = 0 )
print("Read in libraries")
 print("read in train file")
 df=pd.read_csv("/kaggle/input/covid19-global-forecasting-week-2/train.csv",
usecols=['Province_State','Country_Region','Date','ConfirmedCases','Fatalities'])
 print("fill blanks and add region for counting")
 df.fillna(' ',inplace=True)
 df['Lat']=df['Province_State']+df['Country_Region']
df.drop('Province_State',axis=1,inplace=True)
 df.drop('Country_Region',axis=1,inplace=True)
 countries_list=df.Lat.unique()
df1=[]
for i in countries_list:
df1.append(df[df['Lat']==i])
 print("we have "+ str(len(df1)) +" regions in our dataset")
 test=pd.read_csv("/kaggle/input/covid19-global-forecasting-week-2/test.csv")
 submit_confirmed=[]
submit_fatal=[]
for i in df1:
data = i.ConfirmedCases.astype('int32' ).tolist()
try:
model = SARIMAX(data, order=(1,1,0), seasonal_order=(1,1,0,12),measurement_error=True)
 model_fit = model.fit(disp=False)
 predicted = model_fit.predict(len(data), len(data)+34)
 new=np.concatenate(( np.array(data),np.array([int(num)for num in predicted])) ,axis=0)
 submit_confirmed.extend(list(new[-43:]))
except:
submit_confirmed.extend(list(data[-10:-1]))
for j in range(34):
submit_confirmed.append(data[-1]*2)
 data = i.Fatalities.astype('int32' ).tolist()
try:
model = SARIMAX(data, order=(1,1,0), seasonal_order=(1,1,0,12),measurement_error=True)
 model_fit = model.fit(disp=False)
 predicted = model_fit.predict(len(data), len(data)+34)
 new=np.concatenate(( np.array(data),np.array([int(num)for num in predicted])) ,axis=0)
 submit_fatal.extend(list(new[-43:]))
except:
submit_fatal.extend(list(data[-10:-1]))
for j in range(34):
submit_fatal.append(data[-1]*2)
 df_submit=pd.concat([pd.Series(np.arange(1,1+len(submit_confirmed))),pd.Series(submit_confirmed),pd.Series(submit_fatal)],axis=1)
 df_submit=df_submit.fillna(method='pad' ).astype(int)
 df_submit.head()
df_submit.rename(columns={0: 'ForecastId', 1: 'ConfirmedCases',2: 'Fatalities',}, inplace=True )<data_type_conversions>
def huber_loss(y_true, y_pred, clip_delta=1.0):
error = y_true - y_pred
cond = tf.keras.backend.abs(error)< clip_delta
squared_loss = 0.5 * tf.keras.backend.square(error)
 linear_loss = clip_delta *(tf.keras.backend.abs(error)- 0.5 * clip_delta)
 return tf.where(cond, squared_loss, linear_loss)
 def huber_loss_mean(y_true, y_pred, clip_delta=1.0):
return tf.keras.backend.mean(huber_loss(y_true, y_pred, clip_delta))
def rmsle(y, y_pred):
assert len(y)== len(y_pred)
 terms_to_sum = [(math.log(y_pred[i] + 1)- math.log(y[i] + 1)) ** 2.0 for i,pred in enumerate(y_pred)]
return(sum(terms_to_sum)*(1.0/len(y)))** 0.5
sub.rename(columns={'ForecastId': 'ForecastId1', "ConfirmedCases": 'Confirmed_lgbt',"Fatalities": 'Fatalities_lgbt',}, inplace=True)
 df_submit.rename(columns={'ForecastId': 'ForecastId2', "ConfirmedCases": 'Confirmed_arima',"Fatalities": 'Fatalities_arima',}, inplace=True)
 df_submit.shape
df_combine = pd.concat([sub, df_submit], axis=1, join='inner')
 cols = ['Confirmed_lgbt','Confirmed_arima']
df_combine['ConfirmedCases'] = df_combine[cols].astype(float ).mean(axis=1)
 cols = ['Fatalities_lgbt','Fatalities_arima']
df_combine['Fatalities'] = df_combine[cols].astype(float ).mean(axis=1)
 del df_combine['ForecastId2']
del df_combine['Confirmed_lgbt']
del df_combine['Fatalities_lgbt']
del df_combine['Confirmed_arima']
del df_combine['Fatalities_arima']
df_combine.head()
df_combine.rename(columns={'ForecastId1': 'ForecastId', "ConfirmedCases": 'ConfirmedCases',"Fatalities": 'Fatalities',}, inplace=True)
 df_combine.to_csv('submission.csv',index=False)
 test=pd.read_csv("/kaggle/input/covid19-global-forecasting-week-2/test.csv")
 complete_test= pd.merge(test, df_combine, how="left", on="ForecastId")
 complete_test.to_csv('complete_test.csv',index=False)
<set_options>
epochs_num = 10
n_hidden = 200
n_in = 1
model = Sequential()
model.add(GRU(n_hidden,
batch_input_shape=(None, maxlen, n_in),
kernel_initializer='random_uniform',
return_sequences=False))
model.add(Dense(n_in, kernel_initializer='random_uniform'))
model.add(Activation("linear"))
opt = Adagrad(lr=0.01, epsilon=1e-08, decay=1e-4)
 model.compile(loss = huber_loss_mean, optimizer=opt )
warnings.filterwarnings("ignore")
<load_from_csv>
early_stopping = EarlyStopping(monitor='loss', patience=5, verbose=1)
 hist = model.fit(X_train, Y_train, batch_size=10, epochs=epochs_num,
callbacks=[early_stopping],shuffle=False )
datapath = '.. /input/covid19-global-forecasting-week-2/'
train = pd.read_csv(datapath+'train.csv',)
 test = pd.read_csv(datapath+'test.csv' )<data_type_conversions>
predicted_std = model.predict(X_test)
 result_std= pd.DataFrame(predicted_std)
 result_std.columns = ['predict']
result_std['actual'] = Y_test
train['Date'] = train['Date'].astype('datetime64[ns]')
 test['Date'] = test['Date'].astype('datetime64[ns]')
 print("Train Date type: ", train['Date'].dtype)
 print("Test Date type: ",test['Date'].dtype )<rename_columns>
predicted = scaler.inverse_transform(predicted_std - abs(confirmedCase_std_min))
Y_test = scaler.inverse_transform(Y_test - abs(confirmedCase_std_min))
train.columns = ['id','state','country','date','ConfirmedCases','Fatalities']
test.columns = ['ForecastId', 'state','country','date']<feature_engineering>
np.sqrt(mean_squared_log_error(predicted, Y_test))
train['place'] = train['state'].fillna('')+ '_' + train['country']
test['place'] = test['state'].fillna('')+ '_' + test['country']<count_unique_values>
result= pd.DataFrame(predicted)
 result.columns = ['predict']
result['actual'] = Y_test
result.plot(figsize=(25,6))
plt.show()
print('How many places?: ', 'Train: ', len(train['place'].unique()),
'Test: ', len(test['place'].unique()))
print('Unique place similar as test?: ',(train['place'].unique() == test['place'].unique() ).sum() )<drop_column>
test_df = pd.read_csv(".. /input/covid19-global-forecasting-week-3/test.csv")
 test_df
china_cases = train[train['place'].str.contains('China')][['date',
'ConfirmedCases',
'Fatalities']].reset_index(drop=True)
 restworld_cases = train[-train['place'].str.contains('China')][['date',
'ConfirmedCases',
'Fatalities']].reset_index(drop=True )<drop_column>
submission_c = pd.read_csv(".. /input/covid19-global-forecasting-week-3/submission.csv" )
us_cases = train[train['place'].str.contains('US')][['date','place',
'ConfirmedCases',
'Fatalities']].reset_index(drop=True )<compute_test_metric>
temp =(datetime.datetime.strptime("2020-03-25", '%Y-%m-%d')- datetime.timedelta(days=maxlen)).strftime('%Y-%m-%d')
 test_df = train_df[train_df["Date"] > temp]
def RMSLE(predicted, actual):
return np.sqrt(np.mean(np.power(( np.log(predicted+1)-np.log(actual+1)) ,2)) )<feature_engineering>
check_df = pd.read_csv(".. /input/covid19-global-forecasting-week-3/train.csv" ).query("Date>'2020-03-25'and Date<='2020-04-07'")
 check_df["ConfirmedCases_std"] = scaler.transform(check_df["ConfirmedCases"].values.reshape(len(check_df["ConfirmedCases"].values),1)) + abs(confirmedCase_std_min )
train_sub = train[['id','place','date','ConfirmedCases','Fatalities']]
train_sub['logConfirmedCases'] = np.log(train_sub['ConfirmedCases'])
 train_sub = train_sub.set_index('date' )<feature_engineering>
confirmedCases_pred = []
for i in range(0,306*maxlen,maxlen):
temp_array = np.array(test_df["ConfirmedCases_std"][i:i+maxlen])
 for j in range(43):
if j<13:
temp_array = np.append(temp_array,np.array(check_df["ConfirmedCases_std"])[int(i*13/maxlen)+j])
 elif np.array(test_df["ConfirmedCases"][i:i+maxlen] ).sum() == 0:
temp_array = np.append(temp_array,temp_array[-1])
 else:
pred = model.predict(temp_array[-maxlen:].reshape(1,maxlen,1))
pred = np.where(float(pred)< temp_array[-1],temp_array[-1],pred)
 temp_array = np.append(temp_array,pred)
 confirmedCases_pred.append(temp_array[-43:] )
list= []
for place in train_sub.place.unique() :
a = train_sub[train_sub['place']==place]
a['z_cases'] =(a['logConfirmedCases']- a['logConfirmedCases'].rolling(window=3 ).mean())/a['logConfirmedCases'].rolling(window=3 ).std()
a['zp_cases']= a['z_cases']- a['z_cases'].shift(3)
 a['z_death'] =(a['Fatalities']-a['Fatalities'].rolling(window=3 ).mean())/a['Fatalities'].rolling(window=3 ).std()
a['zp_death']= a['z_death']- a['z_death'].shift(3)
 list.append(a)
 rolling_df = pd.concat(list )<statistical_test>
submission_c["ConfirmedCases"] = np.abs(scaler.inverse_transform(np.array(confirmedCases_pred ).reshape(306*43)- abs(confirmedCase_std_min)))
 submission_c["ConfirmedCases_std"] = np.array(confirmedCases_pred ).reshape(306*43)
 submission_c
stationary_data =[]
for place in train_sub.place.unique() :
a= rolling_df[(rolling_df['place']==place)&(rolling_df['logConfirmedCases'] > 0)]['logConfirmedCases'].dropna()
try:
dftest = adfuller(a, autolag='AIC')
 if(dftest[1] < 0.001):
stationary_data.append(place)
 else:
pass
except:
pass
print(len(stationary_data))<count_unique_values>
submission_c.to_csv('./submission_c.csv')
 submission_c.to_csv('.. \output\kaggle\working\submission_c.csv' )
station_death_data =[]
for place in train_sub.place.unique() :
dftest = adfuller(rolling_df[rolling_df['place']==place]['Fatalities'], autolag='AIC')
 if(dftest[1] < 0.001):
station_death_data.append(place)
 else:
pass
print(len(station_death_data))<define_variables>
test_rate = 0.05
maxlen = 13
train_date_count = len(set(train_df["Date"]))
X, Y = [],[]
scaler = StandardScaler()
train_df["Fatalities_std"] = scaler.fit_transform(train_df["Fatalities"].values.reshape(len(train_df["Fatalities"].values),1))
fatalities_std_min = train_df["Fatalities_std"].min()
train_df["Fatalities_std"] = train_df["Fatalities_std"] + abs(fatalities_std_min)
 ss = StandardScaler()
train_df["ConfirmedCases_std"] = ss.fit_transform(train_df["ConfirmedCases"].values.reshape(len(train_df["ConfirmedCases"].values),1))
confirmedCase_std_min = train_df["ConfirmedCases_std"].min()
train_df["ConfirmedCases_std"] = train_df["ConfirmedCases_std"] + abs(confirmedCase_std_min)
 for state,country in train_df.groupby(["Province_State","Country_Region"] ).sum().index:
df = train_df[(train_df["Country_Region"] == country)&(train_df["Province_State"] == state)]
if df["Fatalities"].sum() != 0 or df["ConfirmedCases"].sum() != 0:
for i in range(len(df)- maxlen):
X.append(df[['Fatalities_std','ConfirmedCases_std']].iloc[i:(i+maxlen)].values)
 Y.append(df[['Fatalities_std']].iloc[i+maxlen].values)
 X=np.array(X)
 Y=np.array(Y)
 X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=test_rate, shuffle = True ,random_state = 0 )
confirmedc_lag = ['Anhui_China', 'Chongqing_China','Guangdong_China',
'Guizhou_China', 'Hainan_China', 'Hebei_China','Hubei_China',
'Ningxia_China','Shandong_China','Shanxi_China', 'Sichuan_China']<define_variables>
epochs_num = 30
n_hidden = 200
n_in = 2
model = Sequential()
model.add(GRU(n_hidden,
batch_input_shape=(None, maxlen, n_in),
kernel_initializer='random_uniform',
return_sequences=False))
model.add(Dense(1, kernel_initializer='random_uniform'))
model.add(Activation("linear"))
opt = Adagrad(lr=0.01, epsilon=1e-08, decay=1e-4)
 model.compile(loss = huber_loss_mean, optimizer=opt )
fatalities_lag = ['Hubei_China']<drop_column>
early_stopping = EarlyStopping(monitor='loss', patience=5, verbose=1)
 hist = model.fit(X_train, Y_train, batch_size=8, epochs=epochs_num,
callbacks=[early_stopping],shuffle=False )
non_stationary_death_data = [ele for ele in allplaces]
for place in fatalities_lag:
if place in allplaces:
non_stationary_death_data.remove(place)
 print(len(non_stationary_death_data))<feature_engineering>
predicted_std = model.predict(X_test)
 result_std= pd.DataFrame(predicted_std)
 result_std.columns = ['predict']
result_std['actual'] = Y_test
train_sub['logConfirmedCases']= train_sub['logConfirmedCases'].replace(to_replace=-inf,
value=0 )<merge>
predicted = scaler.inverse_transform(predicted_std - abs(fatalities_std_min))
Y_test = scaler.inverse_transform(Y_test - abs(fatalities_std_min))
poly_data = train[['date','place',
'ConfirmedCases','Fatalities']].merge(test[['date','place']],
how='outer',
on=['date','place'] ).sort_values(['place',
'date'])
 print(poly_data.date.min() , test.date.min() , train.date.max() , poly_data.date.max() )<feature_engineering>
X_test_ = scaler.inverse_transform(X_test - abs(fatalities_std_min))
label = []
for place in poly_data.place.unique() :
labelrange = range(1,len(poly_data[poly_data['place']==place])+1)
 label.append([i for i in labelrange])
 lab = [item for lab in label for item in lab]
poly_data['label'] = lab
poly_data.head()<create_dataframe>
submission_df = submission_c
XYtrain['intercept']= -1
result=pd.DataFrame()
for place in poly_data.place.unique() :
for degree in [2,3,4,5,6]:
features = XYtrain[XYtrain['place']==place][['label','intercept']]
target = XYtrain[XYtrain['place']==place]['ConfirmedCases']
model = make_pipeline(PolynomialFeatures(degree), Ridge())
 model.fit(np.array(features), target)
 y_pred = model.predict(np.array(features))
rmsle = RMSLE(y_pred, target)
 result = result.append(pd.DataFrame({'place':[place],
'degree':[degree],'RMSLE': [rmsle]})) 
<count_unique_values>
temp =(datetime.datetime.strptime("2020-03-25", '%Y-%m-%d')- datetime.timedelta(days=maxlen)).strftime('%Y-%m-%d')
 test_df = train_df[train_df["Date"] > temp]
best_degree = pd.DataFrame()
for place in result.place.unique() :
a = result[result['place']==place]
best_degree = best_degree.append(a[a['RMSLE'] == a['RMSLE'].min() ])
 print(best_degree.groupby('degree')['place'].nunique())
 print('Zero polynomial(no fit): ',best_degree[best_degree['RMSLE']<0.00001]['place'].unique() )<count_unique_values>
check_df["Fatalities_std"] = scaler.transform(check_df["Fatalities"].values.reshape(len(check_df["Fatalities"].values),1)) + abs(fatalities_std_min)
 check_df
fit_best_degree = best_degree[best_degree['RMSLE']>0.00001]
twodeg_places = fit_best_degree[fit_best_degree['degree']==2]['place'].unique()
threedeg_places = fit_best_degree[fit_best_degree['degree']==3]['place'].unique()
fourdeg_places = fit_best_degree[fit_best_degree['degree']==4]['place'].unique()
fivedeg_places = fit_best_degree[fit_best_degree['degree']==5]['place'].unique()
sdeg_places = fit_best_degree[fit_best_degree['degree']==6]['place'].unique()
nofit_places1 = best_degree[best_degree['RMSLE']<0.00001]['place'].unique()
print(fit_best_degree.nunique())
 print(len(twodeg_places), len(threedeg_places),
len(fourdeg_places), len(fivedeg_places), len(sdeg_places), len(nofit_places1))<feature_engineering>
fatalities_pred = []
for i in range(0,306*maxlen,maxlen):
temp_array = np.array(test_df[["Fatalities_std","ConfirmedCases_std"]][i:i+maxlen])
 for j in range(43):
if j<13:
temp_array = np.append(temp_array,np.append(np.array(check_df["Fatalities_std"])[int(i*13/maxlen)+j],np.array(check_df["ConfirmedCases_std"])[int(i*13/maxlen)+j] ).reshape(1,2),axis=0)
 elif np.array(test_df[["Fatalities","ConfirmedCases"]][i:i+maxlen] ).sum() == 0:
temp_array = np.append(temp_array,np.array(temp_array[-1] ).reshape(1,2),axis=0)
 else:
pred = model.predict(temp_array[-maxlen:].reshape(1,maxlen,2))
pred = np.where(pred<temp_array[-1][0],temp_array[-1][0],pred)
 temp_array = np.append(temp_array,np.append(pred,submission_df["ConfirmedCases_std"][i/maxlen*43+j] ).reshape(1,2),axis=0)
 fatalities_pred.append(temp_array[-43:] )
XYtest = XYtest.reset_index(drop=True)
 XYtest['intercept'] = -1<choose_model_class>
submission_df["Fatalities"] = np.abs(scaler.inverse_transform([i[0] - abs(fatalities_std_min)for i in np.array(fatalities_pred ).reshape(306*43,2)]))
submission_df
poly_predicted_confirmedcases = pd.DataFrame()
for place in twodeg_places:
features = XYtrain[XYtrain['place']==place][['label','intercept']]
target = XYtrain[XYtrain['place']==place]['ConfirmedCases']
Xtest = XYtest[XYtest['place']==place][['label','intercept']]
model = make_pipeline(PolynomialFeatures(2), Ridge())
 model.fit(np.array(features), target)
 y_pred = model.predict(np.array(Xtest))
a = pd.DataFrame(zip(XYtrain[XYtrain['place']==place]['place'],
y_pred),columns=['place','ConfirmedCases'])
 poly_predicted_confirmedcases = poly_predicted_confirmedcases.append(a)
 for place in threedeg_places:
features = XYtrain[XYtrain['place']==place][['label','intercept']]
target = XYtrain[XYtrain['place']==place]['ConfirmedCases']
Xtest = XYtest[XYtest['place']==place][['label','intercept']]
model = make_pipeline(PolynomialFeatures(3), Ridge())
 model.fit(np.array(features), target)
 y_pred = model.predict(np.array(Xtest))
b = pd.DataFrame(zip(XYtrain[XYtrain['place']==place]['place'],
y_pred.tolist()),columns=['place','ConfirmedCases'])
 poly_predicted_confirmedcases = poly_predicted_confirmedcases.append(b)
 for place in fourdeg_places:
features = XYtrain[XYtrain['place']==place][['label','intercept']]
target = XYtrain[XYtrain['place']==place]['ConfirmedCases']
Xtest = XYtest[XYtest['place']==place][['label','intercept']]
model = make_pipeline(PolynomialFeatures(4), Ridge())
 model.fit(np.array(features), target)
 y_pred = model.predict(np.array(Xtest))
c = pd.DataFrame(zip(XYtrain[XYtrain['place']==place]['place'],
y_pred.tolist()),columns=['place','ConfirmedCases'])
 poly_predicted_confirmedcases = poly_predicted_confirmedcases.append(c)
 for place in fivedeg_places:
features = XYtrain[XYtrain['place']==place][['label','intercept']]
target = XYtrain[XYtrain['place']==place]['ConfirmedCases']
Xtest = XYtest[XYtest['place']==place][['label','intercept']]
model = make_pipeline(PolynomialFeatures(5), Ridge())
 model.fit(np.array(features), target)
 y_pred = model.predict(np.array(Xtest))
d = pd.DataFrame(zip(XYtrain[XYtrain['place']==place]['place'],
y_pred.tolist()),columns=['place','ConfirmedCases'])
 poly_predicted_confirmedcases = poly_predicted_confirmedcases.append(d)
 for place in sdeg_places:
features = XYtrain[XYtrain['place']==place][['label','intercept']]
target = XYtrain[XYtrain['place']==place]['ConfirmedCases']
Xtest = XYtest[XYtest['place']==place][['label','intercept']]
model = make_pipeline(PolynomialFeatures(6), Ridge())
 model.fit(np.array(features), target)
 y_pred = model.predict(np.array(Xtest))
e = pd.DataFrame(zip(XYtrain[XYtrain['place']==place]['place'],
y_pred.tolist()),columns=['place','ConfirmedCases'])
 poly_predicted_confirmedcases = poly_predicted_confirmedcases.append(e)
<statistical_test>
submission_df[["ConfirmedCases","Fatalities"]] = submission_df[["ConfirmedCases","Fatalities"]].round().astype(int)
 submission_df
fatalities_result=pd.DataFrame()
for place in poly_data.place.unique() :
for degree in [2,3,4,5,6]:
features = XYtrain[XYtrain['place']==place][['label','intercept']]
target = XYtrain[XYtrain['place']==place]['Fatalities']
model = make_pipeline(PolynomialFeatures(degree), Ridge())
 model.fit(np.array(features), target)
 y_pred = model.predict(np.array(features))
rmsle = RMSLE(y_pred, target)
 fatalities_result = fatalities_result.append(pd.DataFrame({'place':[place],
'degree':[degree],'RMSLE': [rmsle]}))<count_unique_values>
submission_df = submission_df.drop("ConfirmedCases_std",axis=1 )
fat_best_degree = pd.DataFrame()
for place in fatalities_result.place.unique() :
a = fatalities_result[fatalities_result['place']==place]
fat_best_degree = fat_best_degree.append(a[a['RMSLE'] == a['RMSLE'].min() ])
 print(fat_best_degree.groupby('degree')['place'].nunique())
 print('Zero polynomial(no fit): ',
fat_best_degree[fat_best_degree['RMSLE']<0.000001]['place'].unique() )<count_unique_values>
submission_df = submission_df.set_index('ForecastId' )
fit_best_degree = fat_best_degree[fat_best_degree['RMSLE']>0.000001]
twodeg_places = fit_best_degree[fit_best_degree['degree']==2]['place'].unique()
threedeg_places = fit_best_degree[fit_best_degree['degree']==3]['place'].unique()
fourdeg_places = fit_best_degree[fit_best_degree['degree']==4]['place'].unique()
fivedeg_places = fit_best_degree[fit_best_degree['degree']==5]['place'].unique()
sevdeg_places = fit_best_degree[fit_best_degree['degree']==6]['place'].unique()
nofit_places2 = fat_best_degree[fat_best_degree['RMSLE']<0.000001]['place'].unique()
print(fit_best_degree.nunique())
 print(len(twodeg_places), len(threedeg_places),
len(fourdeg_places), len(fivedeg_places), len(sevdeg_places), len(nofit_places2))<choose_model_class>
submission_df.to_csv('submission.csv' )