Kaggle competition: COVID19 Global Forecasting (Week 3)
KNN.score(X_test,y_test )<predict_on_test>
import pandas as pd
from pathlib import Path
from pandas_profiling import ProfileReport
from sklearn.tree import DecisionTreeClassifier
from sklearn.preprocessing import LabelEncoder
import datetime
from sklearn.model_selection import GridSearchCV
from sklearn import preprocessing
from sklearn.model_selection import cross_val_score
predict=KNN.predict(test_data.drop('RefId',axis=1))<prepare_output>
base_dir='/kaggle/input/covid19-global-forecasting-week-3/'
train_file='train.csv'
test_file='test.csv'
submit_file='submission.csv'
Submission=pd.DataFrame(data=predict,columns=['IsBadBuy'])
 Submission.head()<prepare_output>
train_df = pd.read_csv(base_dir+'train.csv')
 test_df = pd.read_csv(base_dir+'test.csv')
 submission = pd.read_csv(base_dir+'submission.csv' )
Submission['RefId']=test_data['RefId']
Submission.set_index('RefId',inplace=True )<save_to_csv>
train=train_df.copy()
test= test_df.copy()
Submission.head()
Submission.to_csv('Submission.csv' )<load_from_csv>
train['Province_State'][train.Province_State.isna() ] = train['Country_Region'][train.Province_State.isna() ]
test['Province_State'][test.Province_State.isna() ] = test['Country_Region'][test.Province_State.isna() ]
train_data=pd.read_csv('/kaggle/input/DontGetKicked/training.csv')
 train_data.head()<load_from_csv>
def decomposedate(df):
df['Date'] = pd.to_datetime(df['Date'],infer_datetime_format=True)
 df['Day_of_Week']=df['Date'].dt.dayofweek
df['Month'] = df['Date'].dt.month
df['Day'] = df['Date'].dt.day
df['Day_of_Year'] = df['Date'].dt.dayofyear
df['Week_of_Year'] = df['Date'].dt.weekofyear
df['Quarter'] = df['Date'].dt.quarter
df.drop('Date',1,inplace=True)
 return df
test_data=pd.read_csv('/kaggle/input/DontGetKicked/test.csv')
 test_data.head()<count_missing_values>
train=decomposedate(train)
 test=decomposedate(test )
train_data.isnull().sum()<count_missing_values>
submission=pd.DataFrame(columns=submission.columns )
test_data.isnull().sum()<count_values>
l1=LabelEncoder()
l2=LabelEncoder()
train_data['IsBadBuy'].value_counts()<count_values>
train['Country_Region']=l1.fit_transform(train['Country_Region'])
 train['Province_State']=l2.fit_transform(train['Province_State'] )
train_data['Model'].value_counts()<drop_column>
test['Country_Region']=l1.fit_transform(test['Country_Region'])
 test['Province_State']=l2.fit_transform(test['Province_State'] )
train_data.drop('Model',axis=1,inplace=True)
 test_data.drop("Model",axis=1,inplace=True )<count_values>
y1=train[['ConfirmedCases']]
y2=train[['Fatalities']]
test_id=test['ForecastId'].values.tolist()
train_data['Trim'].value_counts()<drop_column>
train.pop('Id')
 test.pop('ForecastId' )
train_data.drop('Trim',inplace=True,axis=1)
 test_data.drop('Trim',inplace=True,axis=1 )<count_values>
features_cols=['Province_State','Country_Region','Day_of_Week','Month','Day','Day_of_Year','Week_of_Year','Quarter']
train_data['SubModel'].value_counts()<drop_column>
train_x=train[features_cols]
test_x = test[features_cols]
train_data.drop('SubModel',inplace=True,axis=1)
 test_data.drop('SubModel',inplace=True,axis=1 )<count_values>
model_1=DecisionTreeClassifier()
model_2=DecisionTreeClassifier()
model_1.fit(train_x,y1)
 model_2.fit(train_x,y2 )
train_data['Color'].value_counts()<count_values>
test_y1=model_1.predict(test_x)
 test_y2=model_2.predict(test_x)
 submission=pd.DataFrame(columns=submission.columns)
 submission['ForecastId']=test_id
submission['ConfirmedCases']=test_y1
submission['Fatalities']=test_y2
test_data['Color'].value_counts()<data_type_conversions>
submission.to_csv('submission.csv',index=False )