{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"\nimport datetime as dt\nimport warnings\n\nimport numpy as np\nimport pandas as pd\nfrom scipy import signal\nfrom scipy.signal import find_peaks\nfrom sklearn.ensemble import IsolationForest\n\n#--- Need Plotly for plotting-------------\nimport plotly.express as px\nimport plotly.graph_objects as go\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:20.390030Z","iopub.execute_input":"2022-07-31T15:30:20.390491Z","iopub.status.idle":"2022-07-31T15:30:20.405208Z","shell.execute_reply.started":"2022-07-31T15:30:20.390441Z","shell.execute_reply":"2022-07-31T15:30:20.404275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"oilprice= pd.read_csv('../input/store-sales-time-series-forecasting/oil.csv')\nholiday = pd.read_csv('../input/store-sales-time-series-forecasting/holidays_events.csv')\ntrain = pd.read_csv('../input/store-sales-time-series-forecasting/train.csv')\ntransactions = pd.read_csv('../input/store-sales-time-series-forecasting/transactions.csv')\nstores= pd.read_csv('../input/store-sales-time-series-forecasting/stores.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:20.414589Z","iopub.execute_input":"2022-07-31T15:30:20.417134Z","iopub.status.idle":"2022-07-31T15:30:22.805190Z","shell.execute_reply.started":"2022-07-31T15:30:20.417090Z","shell.execute_reply":"2022-07-31T15:30:22.804028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# preprocessing\n*Oil Price*","metadata":{}},{"cell_type":"code","source":"oilprice_df = oilprice.fillna(method='bfill')","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:22.807049Z","iopub.execute_input":"2022-07-31T15:30:22.807466Z","iopub.status.idle":"2022-07-31T15:30:22.820399Z","shell.execute_reply.started":"2022-07-31T15:30:22.807434Z","shell.execute_reply":"2022-07-31T15:30:22.819042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Holiday*","metadata":{}},{"cell_type":"code","source":"holiday['isHoliday']=1\nholiday.rename(columns={'type' : 'holidayType'}, inplace=True)\nholiday_df = holiday[['date','isHoliday','holidayType']]","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:22.822071Z","iopub.execute_input":"2022-07-31T15:30:22.822450Z","iopub.status.idle":"2022-07-31T15:30:22.839764Z","shell.execute_reply.started":"2022-07-31T15:30:22.822405Z","shell.execute_reply":"2022-07-31T15:30:22.838774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*train*","metadata":{}},{"cell_type":"code","source":"train.drop('id', axis=1,inplace=True)\ndf = pd.merge(train, holiday_df, on='date', how='left')\ndf.loc[df['isHoliday'].isna(), 'holidayType'] = 'Not_holiday'\n\ndf.loc[df['isHoliday'].isna(), 'isHoliday'] = 0\n","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:22.842571Z","iopub.execute_input":"2022-07-31T15:30:22.843489Z","iopub.status.idle":"2022-07-31T15:30:24.392973Z","shell.execute_reply.started":"2022-07-31T15:30:22.843451Z","shell.execute_reply":"2022-07-31T15:30:24.391734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.merge(df, oilprice, on='date', how='left')\ndf['dcoilwtico'].fillna(method='bfill', inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:24.395021Z","iopub.execute_input":"2022-07-31T15:30:24.395511Z","iopub.status.idle":"2022-07-31T15:30:25.368453Z","shell.execute_reply.started":"2022-07-31T15:30:24.395456Z","shell.execute_reply":"2022-07-31T15:30:25.367233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### let's explore data a bit :)","metadata":{}},{"cell_type":"code","source":"\ntemp  = df.groupby('date')[['sales','dcoilwtico','isHoliday']].agg({'sales':'sum', 'dcoilwtico':'mean' , 'isHoliday':'max'})","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:25.369969Z","iopub.execute_input":"2022-07-31T15:30:25.370992Z","iopub.status.idle":"2022-07-31T15:30:26.071128Z","shell.execute_reply.started":"2022-07-31T15:30:25.370954Z","shell.execute_reply":"2022-07-31T15:30:26.070228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.graph_objects as go\nfrom plotly.subplots import make_subplots\n\nfig = make_subplots(specs=[[{\"secondary_y\": True}]])\n\nfig.add_trace(\n    go.Scatter(x=temp.index, y=temp.sales, name=\"sales\", mode=\"markers\"),\n    secondary_y=False\n)\nfig.add_trace(\n    go.Scatter(x=temp.index, y=temp.dcoilwtico, name=\"WTI oil price\", mode=\"lines\"),\n    secondary_y=True, \n)\nfig.add_trace(\n    go.Scatter(x=temp[temp['isHoliday']==1].index, \n               y=temp['isHoliday'][temp['isHoliday']==1] * temp['sales'][temp['isHoliday']==1], name=\"Holiday\", mode=\"markers\"),\n    secondary_y=False, \n)\nfig.update_xaxes(title_text=\"Date\")\nfig.update_yaxes(title_text=\"Sales\", secondary_y=False)\nfig.update_yaxes(title_text=\"WTI oil price\", secondary_y=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:26.072540Z","iopub.execute_input":"2022-07-31T15:30:26.073799Z","iopub.status.idle":"2022-07-31T15:30:26.398340Z","shell.execute_reply.started":"2022-07-31T15:30:26.073751Z","shell.execute_reply":"2022-07-31T15:30:26.397195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"##### earthquake struck Ecuador on April 16, 2016. People rallied in relief efforts donating water and other first need products which greatly affected supermarket sales for several weeks after the earthquake. It seems some outliers exist in our data lets remove this by the help of the Isolation forest. ","metadata":{}},{"cell_type":"code","source":"model=IsolationForest(n_estimators=50, max_samples='auto', contamination=float(0.1),max_features=1.0)\nmodel.fit(temp['sales'].values.reshape(-1,1))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:26.399872Z","iopub.execute_input":"2022-07-31T15:30:26.400882Z","iopub.status.idle":"2022-07-31T15:30:26.570275Z","shell.execute_reply.started":"2022-07-31T15:30:26.400842Z","shell.execute_reply":"2022-07-31T15:30:26.569073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp['anomaly'] = model.decision_function(temp['sales'].values.reshape(-1,1))\ntemp['anomaly'] = np.where( temp['anomaly'] <0, 'outlier' , 'normal')\n","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:26.571570Z","iopub.execute_input":"2022-07-31T15:30:26.571923Z","iopub.status.idle":"2022-07-31T15:30:26.628327Z","shell.execute_reply.started":"2022-07-31T15:30:26.571867Z","shell.execute_reply":"2022-07-31T15:30:26.627199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"px.histogram(temp , x='sales',color='anomaly', marginal='box')","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:26.633896Z","iopub.execute_input":"2022-07-31T15:30:26.634266Z","iopub.status.idle":"2022-07-31T15:30:27.654887Z","shell.execute_reply.started":"2022-07-31T15:30:26.634232Z","shell.execute_reply":"2022-07-31T15:30:27.653723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"possible_outlier_days= temp[temp['anomaly']=='outlier'].index","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:27.657178Z","iopub.execute_input":"2022-07-31T15:30:27.657577Z","iopub.status.idle":"2022-07-31T15:30:27.664671Z","shell.execute_reply.started":"2022-07-31T15:30:27.657543Z","shell.execute_reply":"2022-07-31T15:30:27.663099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"stores.rename(columns={'type' : 'storeType'}, inplace = True)\nstores_df= stores[['store_nbr' ,'storeType','city','cluster']]","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:27.666402Z","iopub.execute_input":"2022-07-31T15:30:27.667225Z","iopub.status.idle":"2022-07-31T15:30:27.677292Z","shell.execute_reply.started":"2022-07-31T15:30:27.667167Z","shell.execute_reply":"2022-07-31T15:30:27.676093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.merge(df, stores_df, on='store_nbr', how='left')\n\n#since we do not have transactions on the test set, so it is better to remove the transactions from the train set:(\n# df = pd.merge(df, transactions, on=['store_nbr','date'], how='left')\n","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:27.679408Z","iopub.execute_input":"2022-07-31T15:30:27.680075Z","iopub.status.idle":"2022-07-31T15:30:28.898800Z","shell.execute_reply.started":"2022-07-31T15:30:27.680021Z","shell.execute_reply":"2022-07-31T15:30:28.897823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# df['transactions'].fillna(0, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:28.900398Z","iopub.execute_input":"2022-07-31T15:30:28.901135Z","iopub.status.idle":"2022-07-31T15:30:28.905865Z","shell.execute_reply.started":"2022-07-31T15:30:28.901089Z","shell.execute_reply":"2022-07-31T15:30:28.904774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:28.907587Z","iopub.execute_input":"2022-07-31T15:30:28.908257Z","iopub.status.idle":"2022-07-31T15:30:28.942724Z","shell.execute_reply.started":"2022-07-31T15:30:28.908211Z","shell.execute_reply":"2022-07-31T15:30:28.941887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"we can see in the sum ","metadata":{}},{"cell_type":"code","source":"px.imshow(df.corr())","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:28.944081Z","iopub.execute_input":"2022-07-31T15:30:28.944601Z","iopub.status.idle":"2022-07-31T15:30:29.558569Z","shell.execute_reply.started":"2022-07-31T15:30:28.944568Z","shell.execute_reply":"2022-07-31T15:30:29.557453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:29.560005Z","iopub.execute_input":"2022-07-31T15:30:29.560426Z","iopub.status.idle":"2022-07-31T15:30:31.249655Z","shell.execute_reply.started":"2022-07-31T15:30:29.560395Z","shell.execute_reply":"2022-07-31T15:30:31.248353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import OrdinalEncoder\n\nencoder_holidays = OrdinalEncoder()\nencoder_holidays.fit(df['holidayType'].values.reshape(-1,1))\ndf['holidayType'] = encoder_holidays.transform(df['holidayType'].values.reshape(-1,1))\n\n","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:31.251358Z","iopub.execute_input":"2022-07-31T15:30:31.252040Z","iopub.status.idle":"2022-07-31T15:30:32.364156Z","shell.execute_reply.started":"2022-07-31T15:30:31.251993Z","shell.execute_reply":"2022-07-31T15:30:32.363194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"encoder_family = OrdinalEncoder()\nencoder_family.fit(df['family'].values.reshape(-1,1))\ndf['family'] = encoder_family.transform(df['family'].values.reshape(-1,1))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:32.365395Z","iopub.execute_input":"2022-07-31T15:30:32.365730Z","iopub.status.idle":"2022-07-31T15:30:33.659501Z","shell.execute_reply.started":"2022-07-31T15:30:32.365699Z","shell.execute_reply":"2022-07-31T15:30:33.658370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nencoder_storeType = OrdinalEncoder()\nencoder_storeType.fit(df['storeType'].values.reshape(-1,1))\ndf['storeType'] = encoder_storeType.transform(df['storeType'].values.reshape(-1,1))\n","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:33.661293Z","iopub.execute_input":"2022-07-31T15:30:33.661710Z","iopub.status.idle":"2022-07-31T15:30:34.814977Z","shell.execute_reply.started":"2022-07-31T15:30:33.661667Z","shell.execute_reply":"2022-07-31T15:30:34.813938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nencoder_city = OrdinalEncoder()\nencoder_city.fit(df['city'].values.reshape(-1,1))\ndf['city'] = encoder_city.transform(df['city'].values.reshape(-1,1))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:34.816463Z","iopub.execute_input":"2022-07-31T15:30:34.816911Z","iopub.status.idle":"2022-07-31T15:30:35.962910Z","shell.execute_reply.started":"2022-07-31T15:30:34.816878Z","shell.execute_reply":"2022-07-31T15:30:35.961254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:35.966261Z","iopub.execute_input":"2022-07-31T15:30:35.966874Z","iopub.status.idle":"2022-07-31T15:30:36.005439Z","shell.execute_reply.started":"2022-07-31T15:30:35.966809Z","shell.execute_reply":"2022-07-31T15:30:36.003810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_clean = df[~df['date'].isin(possible_outlier_days)].copy()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:36.007211Z","iopub.execute_input":"2022-07-31T15:30:36.007659Z","iopub.status.idle":"2022-07-31T15:30:36.904147Z","shell.execute_reply.started":"2022-07-31T15:30:36.007615Z","shell.execute_reply":"2022-07-31T15:30:36.902804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\n\ndf_clean['date'] = pd.to_datetime(df_clean['date'])\ndf_clean['dayoftheWeek'] = df_clean['date'].apply(lambda x: x.isoweekday())\ndf_clean['month'] = df_clean['date'].apply(lambda x: x.month)\n\ny = df_clean['sales'] \ndf_clean.drop(['sales','date'], axis=1, inplace=True)\nX= df_clean\n","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:30:36.905750Z","iopub.execute_input":"2022-07-31T15:30:36.906416Z","iopub.status.idle":"2022-07-31T15:31:16.820687Z","shell.execute_reply.started":"2022-07-31T15:30:36.906376Z","shell.execute_reply":"2022-07-31T15:31:16.819551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train,X_test,y_train,y_test = train_test_split(X,y,test_size = 0.2)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:31:16.822127Z","iopub.execute_input":"2022-07-31T15:31:16.823285Z","iopub.status.idle":"2022-07-31T15:31:17.828583Z","shell.execute_reply.started":"2022-07-31T15:31:16.823238Z","shell.execute_reply":"2022-07-31T15:31:17.827693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestRegressor\nRandomForest = RandomForestRegressor(n_estimators = 10)\nRandomForest.fit(X_train,y_train)\nRandomForest.score(X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:31:17.830035Z","iopub.execute_input":"2022-07-31T15:31:17.830414Z","iopub.status.idle":"2022-07-31T15:33:28.435367Z","shell.execute_reply.started":"2022-07-31T15:31:17.830377Z","shell.execute_reply":"2022-07-31T15:33:28.434147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Let's take the model predict the test set","metadata":{}},{"cell_type":"code","source":"test = pd.read_csv('../input/store-sales-time-series-forecasting/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:39:01.640188Z","iopub.execute_input":"2022-07-31T15:39:01.640575Z","iopub.status.idle":"2022-07-31T15:39:01.666155Z","shell.execute_reply.started":"2022-07-31T15:39:01.640543Z","shell.execute_reply":"2022-07-31T15:39:01.665195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ids= test['id'].astype(str).copy()\ntest.drop('id',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:39:02.376763Z","iopub.execute_input":"2022-07-31T15:39:02.377903Z","iopub.status.idle":"2022-07-31T15:39:02.416848Z","shell.execute_reply.started":"2022-07-31T15:39:02.377817Z","shell.execute_reply":"2022-07-31T15:39:02.415711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = pd.merge(test, holiday_df, on='date', how='left')\ndf_test.loc[df_test['isHoliday'].isna(), 'holidayType'] = 'Not_holiday'\ndf_test.loc[df_test['isHoliday'].isna(), 'isHoliday'] = 0","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:39:04.696533Z","iopub.execute_input":"2022-07-31T15:39:04.697277Z","iopub.status.idle":"2022-07-31T15:39:04.718225Z","shell.execute_reply.started":"2022-07-31T15:39:04.697236Z","shell.execute_reply":"2022-07-31T15:39:04.717173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = pd.merge(df_test, oilprice, on='date', how='left')\ndf_test['dcoilwtico'].fillna(method='bfill', inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:39:04.948631Z","iopub.execute_input":"2022-07-31T15:39:04.949608Z","iopub.status.idle":"2022-07-31T15:39:04.970542Z","shell.execute_reply.started":"2022-07-31T15:39:04.949547Z","shell.execute_reply":"2022-07-31T15:39:04.968917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = pd.merge(df_test, stores_df, on='store_nbr', how='left')\n# df_test = pd.merge(df_test, transactions, on=['store_nbr','date'], how='left')","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:39:05.146270Z","iopub.execute_input":"2022-07-31T15:39:05.146764Z","iopub.status.idle":"2022-07-31T15:39:05.165646Z","shell.execute_reply.started":"2022-07-31T15:39:05.146724Z","shell.execute_reply":"2022-07-31T15:39:05.164708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# df_test['transactions'].fillna(0, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:39:05.283124Z","iopub.execute_input":"2022-07-31T15:39:05.284588Z","iopub.status.idle":"2022-07-31T15:39:05.289972Z","shell.execute_reply.started":"2022-07-31T15:39:05.284524Z","shell.execute_reply":"2022-07-31T15:39:05.288812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test['holidayType'] = encoder_holidays.transform(df_test['holidayType'].values.reshape(-1,1))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:39:05.451304Z","iopub.execute_input":"2022-07-31T15:39:05.452168Z","iopub.status.idle":"2022-07-31T15:39:05.469304Z","shell.execute_reply.started":"2022-07-31T15:39:05.452121Z","shell.execute_reply":"2022-07-31T15:39:05.467886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test['family'] = encoder_family.transform(df_test['family'].values.reshape(-1,1))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:39:06.104571Z","iopub.execute_input":"2022-07-31T15:39:06.105042Z","iopub.status.idle":"2022-07-31T15:39:06.122554Z","shell.execute_reply.started":"2022-07-31T15:39:06.105005Z","shell.execute_reply":"2022-07-31T15:39:06.121668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test['storeType'] = encoder_storeType.transform(df_test['storeType'].values.reshape(-1,1))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:39:07.420480Z","iopub.execute_input":"2022-07-31T15:39:07.420926Z","iopub.status.idle":"2022-07-31T15:39:07.438686Z","shell.execute_reply.started":"2022-07-31T15:39:07.420890Z","shell.execute_reply":"2022-07-31T15:39:07.436964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test['city'] = encoder_city.transform(df_test['city'].values.reshape(-1,1))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:39:07.707351Z","iopub.execute_input":"2022-07-31T15:39:07.707767Z","iopub.status.idle":"2022-07-31T15:39:07.726114Z","shell.execute_reply.started":"2022-07-31T15:39:07.707733Z","shell.execute_reply":"2022-07-31T15:39:07.724910Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test['date'] = pd.to_datetime(df_test['date'])\ndf_test['dayoftheWeek'] = df_test['date'].apply(lambda x: x.isoweekday())\ndf_test['month'] = df_test['date'].apply(lambda x: x.month)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:39:08.710921Z","iopub.execute_input":"2022-07-31T15:39:08.711410Z","iopub.status.idle":"2022-07-31T15:39:09.555069Z","shell.execute_reply.started":"2022-07-31T15:39:08.711373Z","shell.execute_reply":"2022-07-31T15:39:09.553738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nsales_test= RandomForest.predict(df_test.drop('date',axis=1))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:39:09.557344Z","iopub.execute_input":"2022-07-31T15:39:09.557728Z","iopub.status.idle":"2022-07-31T15:39:09.842423Z","shell.execute_reply.started":"2022-07-31T15:39:09.557693Z","shell.execute_reply":"2022-07-31T15:39:09.841136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test['sales']  = sales_test\ndf_test['id'] = ids","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:39:33.479172Z","iopub.execute_input":"2022-07-31T15:39:33.479785Z","iopub.status.idle":"2022-07-31T15:39:33.488822Z","shell.execute_reply.started":"2022-07-31T15:39:33.479729Z","shell.execute_reply":"2022-07-31T15:39:33.487910Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test[['id','sales']].set_index('id').to_csv('submit.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:42:13.735224Z","iopub.execute_input":"2022-07-31T15:42:13.735664Z","iopub.status.idle":"2022-07-31T15:42:13.805821Z","shell.execute_reply.started":"2022-07-31T15:42:13.735610Z","shell.execute_reply":"2022-07-31T15:42:13.804447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test['sales'].plot()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T15:41:08.300341Z","iopub.execute_input":"2022-07-31T15:41:08.300901Z","iopub.status.idle":"2022-07-31T15:41:08.539070Z","shell.execute_reply.started":"2022-07-31T15:41:08.300860Z","shell.execute_reply":"2022-07-31T15:41:08.538036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}