Kaggle competition: COVID19 Global Forecasting (Week 2)
submission = pd.read_csv('.. /input/sample_submission.csv')
 X_test = test
submission['target'] = selector.predict_proba(X_test)
 submission.to_csv('submission.csv', index=False )<load_from_csv>
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import RandomForestRegressor
train_df = pd.read_csv(".. /input/train.csv")
 test_df = pd.read_csv(".. /input/test.csv")
 smpsb_df = pd.read_csv(".. /input/sample_submission.csv" )<prepare_x_and_y>
train=pd.read_csv('.. /input/covid19-global-forecasting-week-2/train.csv')
 test=pd.read_csv('.. /input/covid19-global-forecasting-week-2/test.csv')
 submission=pd.read_csv('.. /input/covid19-global-forecasting-week-2/submission.csv')
 print(np.shape(train))
print(np.shape(test))
X_train = train_df.iloc[:, 2:].values
X_test = test_df.iloc[:, 1:].values
y = train_df["target"].values
X_all = np.concatenate([X_train, X_test])
 X_all =(X_all - X_all.mean())/ X_all.std()
X_train = X_all[:X_train.shape[0]]
X_test = X_all[X_train.shape[0]:]<train_on_grid>
train['Province_State'].value_counts()
lcv = LogisticRegressionCV(penalty="l1",
Cs=100,
cv=50,
solver="liblinear",
verbose=50)
 lcv.fit(X_train, y )<train_model>
train['Province_State'].fillna('No Data',inplace=True)
 test['Province_State'].fillna('No Data',inplace=True )
skf = RepeatedStratifiedKFold(n_splits=10, n_repeats=10, random_state=2434)
 y_oof = np.zeros(y.shape)
 y_pred = np.zeros(X_test.shape[0])
 for dev, val in tqdm(skf.split(X_train, y), total=100):
X_dev = X_train[dev]
y_dev = y[dev]
X_val = X_train[val]
lr = LogisticRegression(penalty="l1", C=lcv.C_[0], solver="liblinear")
 lr.fit(X_dev, y_dev)
 y_oof[val] += lr.predict_proba(X_val)[:, 1] / 10
y_pred += lr.predict_proba(X_test)[:, 1] / 100<compute_test_metric>
train['Date']= pd.to_datetime(train['Date'])
 test['Date']= pd.to_datetime(test['Date'] )
roc_auc_score(y, y_oof )<save_to_csv>
def create_time_features(df):
df['date'] = df['Date']
df['hour'] = df['date'].dt.hour
df['dayofweek'] = df['date'].dt.dayofweek
df['quarter'] = df['date'].dt.quarter
df['month'] = df['date'].dt.month
df['year'] = df['date'].dt.year
df['dayofyear'] = df['date'].dt.dayofyear
df['dayofmonth'] = df['date'].dt.day
df['weekofyear'] = df['date'].dt.weekofyear
X = df[['hour','dayofweek','quarter','month','year',
'dayofyear','dayofmonth','weekofyear']]
return X
create_time_features(train)
 create_time_features(test)
 train=train.drop(columns=['Date'],axis=1)
 test=test.drop(columns=['Date'],axis=1)
 train=train.drop(columns=['date'],axis=1)
 test=test.drop(columns=['date'],axis=1 )
smpsb_df["target"] = y_pred
smpsb_df.to_csv("simple_lasso.csv", index=None )<set_options>
train_dummies_Province_State = pd.get_dummies(train['Province_State'])
 test_dummies_Province_State = pd.get_dummies(test['Province_State'])
 train_dummies_Country_Region = pd.get_dummies(train['Country_Region'])
 test_dummies_Country_Region = pd.get_dummies(test['Country_Region'])
 train=train.drop(['Country_Region','Province_State','Id'],axis=1)
 test=test.drop(['Country_Region','Province_State','ForecastId'],axis=1)
 train=pd.concat([train,train_dummies_Province_State,train_dummies_Country_Region],axis=1)
 test=pd.concat([test,test_dummies_Province_State,test_dummies_Country_Region],axis=1)
 train.head()
%matplotlib inline 
<set_options>
model = DecisionTreeRegressor(criterion='mse', splitter='best' )
plt.rcParams['figure.figsize'] = [10, 5]
plt.rcParams['font.size'] = 12<load_from_csv>
model.fit(features,target1 )
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv')
 submit = pd.read_csv('.. /input/sample_submission.csv')
 print(train.shape, test.shape, submit.shape )<count_values>
submission['ConfirmedCases'] = model.predict(test )
print(train.target.value_counts() / train.shape[0] * 100 )<filter>
model.fit(features,target2)
 submission['Fatalities'] = model.predict(test )
train_corr.iloc[[0],:]<drop_column>
submission.round().astype(int )
<define_variables><EOS> 
submission.to_csv('submission.csv',index=False )