{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\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":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-15T05:42:09.826649Z","iopub.execute_input":"2022-07-15T05:42:09.827174Z","iopub.status.idle":"2022-07-15T05:42:09.839562Z","shell.execute_reply.started":"2022-07-15T05:42:09.827136Z","shell.execute_reply":"2022-07-15T05:42:09.837736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from prophet import Prophet","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:09.936603Z","iopub.execute_input":"2022-07-15T05:42:09.938231Z","iopub.status.idle":"2022-07-15T05:42:09.943911Z","shell.execute_reply.started":"2022-07-15T05:42:09.938165Z","shell.execute_reply":"2022-07-15T05:42:09.942690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nfrom matplotlib import pyplot as plt\nfrom sklearn.linear_model import LinearRegression as LR\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:10.018928Z","iopub.execute_input":"2022-07-15T05:42:10.020008Z","iopub.status.idle":"2022-07-15T05:42:10.032852Z","shell.execute_reply.started":"2022-07-15T05:42:10.019950Z","shell.execute_reply":"2022-07-15T05:42:10.031403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=pd.read_csv(\"/kaggle/input/store-sales-time-series-forecasting/train.csv\")\ntest=pd.read_csv(\"/kaggle/input/store-sales-time-series-forecasting/test.csv\")\ntransactions=pd.read_csv(\"/kaggle/input/store-sales-time-series-forecasting/transactions.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:10.069866Z","iopub.execute_input":"2022-07-15T05:42:10.071051Z","iopub.status.idle":"2022-07-15T05:42:12.405047Z","shell.execute_reply.started":"2022-07-15T05:42:10.070996Z","shell.execute_reply":"2022-07-15T05:42:12.403716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"stores=pd.read_csv(\"/kaggle/input/store-sales-time-series-forecasting/stores.csv\")\nholiday=pd.read_csv(\"/kaggle/input/store-sales-time-series-forecasting/holidays_events.csv\")\nsample=pd.read_csv(\"/kaggle/input/store-sales-time-series-forecasting/sample_submission.csv\")\noil=pd.read_csv(\"/kaggle/input/store-sales-time-series-forecasting/oil.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:12.407564Z","iopub.execute_input":"2022-07-15T05:42:12.408738Z","iopub.status.idle":"2022-07-15T05:42:12.436574Z","shell.execute_reply.started":"2022-07-15T05:42:12.408695Z","shell.execute_reply":"2022-07-15T05:42:12.435503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:12.438105Z","iopub.execute_input":"2022-07-15T05:42:12.439160Z","iopub.status.idle":"2022-07-15T05:42:12.454691Z","shell.execute_reply.started":"2022-07-15T05:42:12.439120Z","shell.execute_reply":"2022-07-15T05:42:12.453288Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:12.459240Z","iopub.execute_input":"2022-07-15T05:42:12.459615Z","iopub.status.idle":"2022-07-15T05:42:12.472887Z","shell.execute_reply.started":"2022-07-15T05:42:12.459579Z","shell.execute_reply":"2022-07-15T05:42:12.471480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:12.475325Z","iopub.execute_input":"2022-07-15T05:42:12.476420Z","iopub.status.idle":"2022-07-15T05:42:12.490325Z","shell.execute_reply.started":"2022-07-15T05:42:12.476368Z","shell.execute_reply":"2022-07-15T05:42:12.489286Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"stores.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:12.492256Z","iopub.execute_input":"2022-07-15T05:42:12.493394Z","iopub.status.idle":"2022-07-15T05:42:12.506096Z","shell.execute_reply.started":"2022-07-15T05:42:12.493351Z","shell.execute_reply":"2022-07-15T05:42:12.505206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:12.507415Z","iopub.execute_input":"2022-07-15T05:42:12.507967Z","iopub.status.idle":"2022-07-15T05:42:13.171991Z","shell.execute_reply.started":"2022-07-15T05:42:12.507913Z","shell.execute_reply":"2022-07-15T05:42:13.170700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['year'] = train['date'].apply(lambda x : x.split('-')[0])\ntrain['month'] = train['date'].apply(lambda x : x.split('-')[1])","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:13.173726Z","iopub.execute_input":"2022-07-15T05:42:13.174792Z","iopub.status.idle":"2022-07-15T05:42:16.165219Z","shell.execute_reply.started":"2022-07-15T05:42:13.174744Z","shell.execute_reply":"2022-07-15T05:42:16.164260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:16.166540Z","iopub.execute_input":"2022-07-15T05:42:16.167380Z","iopub.status.idle":"2022-07-15T05:42:16.183695Z","shell.execute_reply.started":"2022-07-15T05:42:16.167330Z","shell.execute_reply":"2022-07-15T05:42:16.182335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.onpromotion = train.onpromotion.astype(\"float16\")\ntrain.sales = train.sales.astype(\"float32\")\nstores.cluster = stores.cluster.astype(\"int8\")","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:16.188799Z","iopub.execute_input":"2022-07-15T05:42:16.189814Z","iopub.status.idle":"2022-07-15T05:42:16.245413Z","shell.execute_reply.started":"2022-07-15T05:42:16.189759Z","shell.execute_reply":"2022-07-15T05:42:16.244221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import datetime","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:16.246691Z","iopub.execute_input":"2022-07-15T05:42:16.247038Z","iopub.status.idle":"2022-07-15T05:42:16.251503Z","shell.execute_reply.started":"2022-07-15T05:42:16.247007Z","shell.execute_reply":"2022-07-15T05:42:16.250635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"date=train['date']","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:16.252756Z","iopub.execute_input":"2022-07-15T05:42:16.253081Z","iopub.status.idle":"2022-07-15T05:42:16.265004Z","shell.execute_reply.started":"2022-07-15T05:42:16.253050Z","shell.execute_reply":"2022-07-15T05:42:16.264126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['ds']=date","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:16.266327Z","iopub.execute_input":"2022-07-15T05:42:16.266869Z","iopub.status.idle":"2022-07-15T05:42:16.326950Z","shell.execute_reply.started":"2022-07-15T05:42:16.266835Z","shell.execute_reply":"2022-07-15T05:42:16.326006Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.rename(columns={'sales':'y'})","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:16.328400Z","iopub.execute_input":"2022-07-15T05:42:16.329030Z","iopub.status.idle":"2022-07-15T05:42:17.541237Z","shell.execute_reply.started":"2022-07-15T05:42:16.328992Z","shell.execute_reply":"2022-07-15T05:42:17.540053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=train.rename(columns={'sales':'y'})","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:17.543163Z","iopub.execute_input":"2022-07-15T05:42:17.543850Z","iopub.status.idle":"2022-07-15T05:42:18.456720Z","shell.execute_reply.started":"2022-07-15T05:42:17.543794Z","shell.execute_reply":"2022-07-15T05:42:18.455537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Prophet()\nmodel.fit(train)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T05:42:18.458027Z","iopub.execute_input":"2022-07-15T05:42:18.458365Z","iopub.status.idle":"2022-07-15T05:52:41.980724Z","shell.execute_reply.started":"2022-07-15T05:42:18.458333Z","shell.execute_reply":"2022-07-15T05:52:41.978766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a=test['date']\ntest['ds']=a","metadata":{"execution":{"iopub.status.busy":"2022-07-15T06:10:15.888915Z","iopub.execute_input":"2022-07-15T06:10:15.889480Z","iopub.status.idle":"2022-07-15T06:10:15.899051Z","shell.execute_reply.started":"2022-07-15T06:10:15.889440Z","shell.execute_reply":"2022-07-15T06:10:15.897869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"forecust=model.predict(test)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T06:10:18.389094Z","iopub.execute_input":"2022-07-15T06:10:18.390615Z","iopub.status.idle":"2022-07-15T06:10:45.531272Z","shell.execute_reply.started":"2022-07-15T06:10:18.390503Z","shell.execute_reply":"2022-07-15T06:10:45.530012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.plot(forecust)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T06:10:50.634448Z","iopub.execute_input":"2022-07-15T06:10:50.635339Z","iopub.status.idle":"2022-07-15T06:11:06.269782Z","shell.execute_reply.started":"2022-07-15T06:10:50.635275Z","shell.execute_reply":"2022-07-15T06:11:06.268129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"s_data = []\ns_id = []\n          \n\ns_data = np.array(s_data).reshape(-1, 128,128,3)\ns_data = s_data.astype('float32')\ns_data /= 255.0","metadata":{"execution":{"iopub.status.busy":"2022-07-15T06:13:53.745413Z","iopub.execute_input":"2022-07-15T06:13:53.745876Z","iopub.status.idle":"2022-07-15T06:13:53.752690Z","shell.execute_reply.started":"2022-07-15T06:13:53.745842Z","shell.execute_reply":"2022-07-15T06:13:53.751429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"s_pred = []\nfor i,img in enumerate(s_data):\n    \n    img = img[None, ...]\n    result = model.predict(img)\n    \n    s_pred.append(result[0][1])","metadata":{"execution":{"iopub.status.busy":"2022-07-15T06:13:58.742091Z","iopub.execute_input":"2022-07-15T06:13:58.742952Z","iopub.status.idle":"2022-07-15T06:13:58.750238Z","shell.execute_reply.started":"2022-07-15T06:13:58.742889Z","shell.execute_reply":"2022-07-15T06:13:58.748465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ansdict = {'id':s_id,'label':s_pred}\ndf = pd.DataFrame(ansdict)\ndf.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T06:14:01.133127Z","iopub.execute_input":"2022-07-15T06:14:01.133556Z","iopub.status.idle":"2022-07-15T06:14:01.145733Z","shell.execute_reply.started":"2022-07-15T06:14:01.133523Z","shell.execute_reply":"2022-07-15T06:14:01.144350Z"},"trusted":true},"execution_count":null,"outputs":[]}]}