Kaggle competition: COVID19 Global Forecasting (Week 3)
Tourney_Results_Compact=Tourney_Results_Compact.drop(['WScore','LScore'],axis=1)
 Tourney_Results_Compact.head()<data_type_conversions>
X_train = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-3/train.csv')
 X_test = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-3/test.csv')
 X_train.rename(columns={'Country_Region':'Country'}, inplace=True)
 X_test.rename(columns={'Country_Region':'Country'}, inplace=True)
 X_train.rename(columns={'Province_State':'State'}, inplace=True)
 X_test.rename(columns={'Province_State':'State'}, inplace=True)
 X_train.Date = pd.to_datetime(X_train.Date, infer_datetime_format=True)
 X_test.Date = pd.to_datetime(X_test.Date, infer_datetime_format=True)
 EMPTY_VAL = "EMPTY_VAL"
def fillState(state, country):
if state == EMPTY_VAL: return country
return state
Tourney_Results_Compact['WinningSeed'] = Tourney_Results_Compact['WinningSeed'].str.extract('(\d+)', expand=True)
 Tourney_Results_Compact['LoosingSeed'] = Tourney_Results_Compact['LoosingSeed'].str.extract('(\d+)', expand=True)
 Tourney_Results_Compact.WinningSeed = pd.to_numeric(Tourney_Results_Compact.WinningSeed, errors='coerce')
 Tourney_Results_Compact.LoosingSeed = pd.to_numeric(Tourney_Results_Compact.LoosingSeed, errors='coerce' )<rename_columns>
X_xTrain = X_train.copy()
X_xTrain.State.fillna(EMPTY_VAL, inplace=True)
 X_xTrain.State = X_xTrain.loc[:, ['State', 'Country']].apply(lambda x : fillState(x['State'], x['Country']), axis=1)
 X_xTrain.loc[:, 'Date'] = X_xTrain.Date.dt.strftime("%m%d")
 X_xTrain.Date = X_xTrain.Date.astype(int)
 X_xTest = X_test.copy()
X_xTest.State.fillna(EMPTY_VAL, inplace=True)
 X_xTest.State = X_xTest.loc[:, ['State', 'Country']].apply(lambda x : fillState(x['State'], x['Country']), axis=1)
 X_xTest.loc[:, 'Date'] = X_xTest.Date.dt.strftime("%m%d")
 X_xTest.Date = X_xTest.Date.astype(int)
season_winning_team = RegularSeason_Compact_Results[['Season', 'WTeamID', 'WScore']]
season_losing_team = RegularSeason_Compact_Results[['Season', 'LTeamID', 'LScore']]
season_winning_team.rename(columns={'WTeamID':'TeamID','WScore':'Score'}, inplace=True)
 season_losing_team.rename(columns={'LTeamID':'TeamID','LScore':'Score'}, inplace=True)
 RegularSeason_Compact_Results = pd.concat(( season_winning_team, season_losing_team)).reset_index(drop=True)
 RegularSeason_Compact_Results<groupby>
le = preprocessing.LabelEncoder()
X_xTrain.Country = le.fit_transform(X_xTrain.Country)
 X_xTrain.State = le.fit_transform(X_xTrain.State)
 X_xTest.Country = le.fit_transform(X_xTest.Country)
 X_xTest.State = le.fit_transform(X_xTest.State )
RegularSeason_Compact_Results_Final = RegularSeason_Compact_Results.groupby(['Season', 'TeamID'])['Score'].sum().reset_index()
RegularSeason_Compact_Results_Final<merge>
filterwarnings('ignore')
 le = preprocessing.LabelEncoder()
countries = X_xTrain.Country.unique()
Tourney_Results_Compact = pd.merge(Tourney_Results_Compact, RegularSeason_Compact_Results_Final, left_on=['Season', 'WTeamID'], right_on=['Season', 'TeamID'], how='left')
 Tourney_Results_Compact.rename(columns={'Score':'WScoreTotal'}, inplace=True)
 Tourney_Results_Compact<save_to_csv>
xout = pd.DataFrame({'ForecastId': [], 'ConfirmedCases': [], 'Fatalities': []})
 for country in countries:
states = X_xTrain.loc[X_xTrain.Country == country, :].State.unique()
for state in states:
X_xTrain_CS = X_xTrain.loc[(X_xTrain.Country == country)&(X_xTrain.State == state), ['State', 'Country', 'Date', 'ConfirmedCases', 'Fatalities']]
y1_xTrain_CS = X_xTrain_CS.loc[:, 'ConfirmedCases']
y2_xTrain_CS = X_xTrain_CS.loc[:, 'Fatalities']
X_xTrain_CS = X_xTrain_CS.loc[:, ['State', 'Country', 'Date']]
X_xTrain_CS.Country = le.fit_transform(X_xTrain_CS.Country)
 X_xTrain_CS.State = le.fit_transform(X_xTrain_CS.State)
 X_xTest_CS = X_xTest.loc[(X_xTest.Country == country)&(X_xTest.State == state), ['State', 'Country', 'Date', 'ForecastId']]
X_xTest_CS_Id = X_xTest_CS.loc[:, 'ForecastId']
X_xTest_CS = X_xTest_CS.loc[:, ['State', 'Country', 'Date']]
X_xTest_CS.Country = le.fit_transform(X_xTest_CS.Country)
 X_xTest_CS.State = le.fit_transform(X_xTest_CS.State)
 xmodel1 = DecisionTreeRegressor()
xmodel1.fit(X_xTrain_CS, y1_xTrain_CS)
 y1_xpred = xmodel1.predict(X_xTest_CS)
 xmodel2 = DecisionTreeRegressor()
xmodel2.fit(X_xTrain_CS, y2_xTrain_CS)
 y2_xpred = xmodel2.predict(X_xTest_CS)
 xdata = pd.DataFrame({'ForecastId': X_xTest_CS_Id, 'ConfirmedCases': y1_xpred, 'Fatalities': y2_xpred})
 xout = pd.concat([xout, xdata], axis=0 )
<drop_column><EOS> 
xout.ForecastId = xout.ForecastId.astype('int')
 xout.tail()
xout.to_csv('submission.csv', index=False )