Kaggle competition: COVID19 Global Forecasting (Week 2)
model_results = cv_model(train_set, train_labels,
RandomForestClassifier(100, random_state=10),
'RF', model_results )<predict_on_test>
from sklearn.tree import DecisionTreeRegressor
from sklearn import preprocessing
def submit(model):
model.fit(train_set, train_labels)
 predictions = model.predict(test_set)
 predictions = pd.DataFrame({'idhogar': test_ids,
'Target': predictions})
 submission = submission_base.merge(predictions,
on = 'idhogar',
how = 'left' ).drop(columns = ['idhogar'])
 submission['Target'] = submission['Target'].fillna(4 ).astype(np.int8)
 return submission<split>
df = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/train.csv')
 df.head()
X_train, X_test, y_train, y_test = train_test_split(train_set, train_labels, test_size = 0.2,
random_state =42 )<import_modules>
df['Date'] = pd.to_datetime(df['Date'])
 df['Date'] = pd.to_timedelta(df.Date ).dt.total_seconds().astype(int)
 df = df.replace(np.nan, '', regex=True)
 le_cr = preprocessing.LabelEncoder()
le_ps = preprocessing.LabelEncoder()
le_cr.fit(df['Country_Region'])
 le_ps.fit(df['Province_State'])
 df['Country_Region'] = le_cr.transform(df['Country_Region'])
 df['Province_State'] = le_ps.transform(df['Province_State'] )
import xgboost
from xgboost import XGBClassifier
from sklearn.metrics import f1_score<compute_train_metric>
regressor_cc = DecisionTreeRegressor(random_state = 0, max_features="sqrt")
 regressor_f = DecisionTreeRegressor(random_state = 0, max_features="sqrt")
 regressor_cc.fit(df[['Country_Region','Province_State','Date']], df[['ConfirmedCases']])
 regressor_f.fit(df[['Country_Region','Province_State','Date']], df[['Fatalities']] )
xgb_model = XGBClassifier(objective = 'multi:softmax', random_state = 42)
 xgb_model.fit(X_train, y_train)
 y_pred = xgb_model.predict(X_test)
 f1_score(y_test, y_pred, average = 'macro' )<filter>
df_test = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/test.csv' )
test_ids = list(final.loc[final['Target'].isnull() , 'idhogar'] )<import_modules>
df_test['Date'] = pd.to_datetime(df_test['Date'])
 df_test['Date'] = pd.to_timedelta(df_test.Date ).dt.total_seconds().astype(int)
 df_test = df_test.replace(np.nan, '', regex=True)
 df_test['Country_Region'] = le_cr.transform(df_test['Country_Region'])
 df_test['Province_State'] = le_ps.transform(df_test['Province_State'] )
import lightgbm
from lightgbm import LGBMClassifier<compute_train_metric>
df_s = pd.DataFrame()
df_s['ForecastId'] = df_test['ForecastId']
df_s['ConfirmedCases'] = regressor_cc.predict(df_test[['Country_Region','Province_State','Date']])
 df_s['Fatalities'] = regressor_f.predict(df_test[['Country_Region','Province_State','Date']] )
<save_to_csv><EOS> 
df_s.to_csv('submission.csv', index=False )