{"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":"2021-11-11T04:18:56.195809Z","iopub.execute_input":"2021-11-11T04:18:56.196447Z","iopub.status.idle":"2021-11-11T04:18:56.227478Z","shell.execute_reply.started":"2021-11-11T04:18:56.19633Z","shell.execute_reply":"2021-11-11T04:18:56.226897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install py7zr\nimport py7zr","metadata":{"execution":{"iopub.status.busy":"2021-11-11T04:18:57.144145Z","iopub.execute_input":"2021-11-11T04:18:57.144565Z","iopub.status.idle":"2021-11-11T04:19:11.039778Z","shell.execute_reply.started":"2021-11-11T04:18:57.144527Z","shell.execute_reply":"2021-11-11T04:19:11.03903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import py7zr\nfrom subprocess import check_output\n\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        archive = py7zr.SevenZipFile(os.path.join(dirname, filename), mode='r')\n        archive.extractall(path=\"/kaggle/working\")\n        archive.close()\n\nprint(check_output([\"ls\", \"../working\"]).decode(\"utf8\"))","metadata":{"execution":{"iopub.status.busy":"2021-11-11T04:19:11.041545Z","iopub.execute_input":"2021-11-11T04:19:11.042348Z","iopub.status.idle":"2021-11-11T04:20:42.741993Z","shell.execute_reply.started":"2021-11-11T04:19:11.042303Z","shell.execute_reply":"2021-11-11T04:20:42.740913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\ndf=pd.read_csv('./train.csv')\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-11T04:22:06.718285Z","iopub.execute_input":"2021-11-11T04:22:06.71859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-11-11T03:47:42.250368Z","iopub.execute_input":"2021-11-11T03:47:42.250635Z","iopub.status.idle":"2021-11-11T03:48:09.661679Z","shell.execute_reply.started":"2021-11-11T03:47:42.250607Z","shell.execute_reply":"2021-11-11T03:48:09.660597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['onpromotion']=df['onpromotion'].fillna('Not Available')\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-11T03:48:09.663737Z","iopub.execute_input":"2021-11-11T03:48:09.664157Z","iopub.status.idle":"2021-11-11T03:48:26.547642Z","shell.execute_reply.started":"2021-11-11T03:48:09.664125Z","shell.execute_reply":"2021-11-11T03:48:26.546379Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['date']=pd.to_datetime(df['date'])","metadata":{"execution":{"iopub.status.busy":"2021-11-11T03:48:26.549109Z","iopub.execute_input":"2021-11-11T03:48:26.549368Z","iopub.status.idle":"2021-11-11T03:48:50.845394Z","shell.execute_reply.started":"2021-11-11T03:48:26.549339Z","shell.execute_reply":"2021-11-11T03:48:50.844407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['2013']","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.loc['2013-01-01':'2013-12-01']\ndf","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport matplotlib\n%matplotlib inline\nmatplotlib.rcParams['figure.figsize']=[12.0,8.0]\nfrom datetime import datetime\ns_d=datetime(2013,1,1)\ne_d=datetime(2013,12,1)\ndf[(s_d<=df['date'].index)&(df['date'].index<=e_d)].plot(grid=True)","metadata":{"execution":{"iopub.status.busy":"2021-11-11T03:56:48.018553Z","iopub.execute_input":"2021-11-11T03:56:48.018916Z","iopub.status.idle":"2021-11-11T03:56:48.062592Z","shell.execute_reply.started":"2021-11-11T03:56:48.018882Z","shell.execute_reply":"2021-11-11T03:56:48.061098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dummy_ = pd.DataFrame(val, index=pd.date_range(start='1/1/1910', end='1/10/1910', freq='D'), \n                      # DateOffset 'D' refers to daily \n                      columns=['RandomData'])","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.index = df['date']\ndf.drop(['date'], axis=1, inplace=True)\n# Changing frequency from daily to month end and getting the mean passenger for each month\ndf.resample('M').mean().head()\n# Note - M is one of the DateOffset object provided by Pandas.\n","metadata":{"execution":{"iopub.status.busy":"2021-11-11T03:44:19.735898Z","iopub.execute_input":"2021-11-11T03:44:19.737067Z","iopub.status.idle":"2021-11-11T03:44:19.835448Z","shell.execute_reply.started":"2021-11-11T03:44:19.736866Z","shell.execute_reply":"2021-11-11T03:44:19.834326Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Importing necessary libraries\nimport matplotlib.pyplot as plt\n# Feching years\nyear = df['date'].dt.year\n# Visualizing the time series by plotting number of passengers versus time\nfig, ax = plt.subplots()\nax.plot(df.unit_sales)\nax.set_title('Unit Sales', weight='bold', fontsize=18) # Title\nax.set_ylabel('Unit Sales', fontsize=15)\nax.set_xlabel('Years', fontsize=15)\nax.set_xticklabels(np.unique(year))\nfig.show()\n","metadata":{"execution":{"iopub.status.busy":"2021-11-11T03:42:09.96894Z","iopub.execute_input":"2021-11-11T03:42:09.969757Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a=df.sample(frac=.1)","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:03:41.247821Z","iopub.execute_input":"2021-11-10T14:03:41.248164Z","iopub.status.idle":"2021-11-10T14:03:57.233153Z","shell.execute_reply.started":"2021-11-10T14:03:41.248126Z","shell.execute_reply":"2021-11-10T14:03:57.232213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:04:10.485168Z","iopub.execute_input":"2021-11-10T14:04:10.485471Z","iopub.status.idle":"2021-11-10T14:04:10.503868Z","shell.execute_reply.started":"2021-11-10T14:04:10.48544Z","shell.execute_reply":"2021-11-10T14:04:10.503285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LinearRegression\nfrom scipy.special import boxcox1p\nimport seaborn as sns\ncols = [c for c in df if c not in ['item_nbr','store_nbr', 'unit_sales', 'date']]\nX_train = df[cols].clip(lower=0)\ny_train = df.unit_sales\n\nregr = linear_model.LinearRegression(fit_intercept = False)\nregr.fit(X_train, y_train)\nplt.plot(regr.coef_, )\ny_pred = regr.predict(ts[cols].clip(lower=0))\ny_pred[0:10]\ny_pred[8740:8760]","metadata":{"execution":{"iopub.status.busy":"2021-11-10T13:52:15.240096Z","iopub.execute_input":"2021-11-10T13:52:15.240632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_1=pd.read_csv('./stores.csv')","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:01:45.514964Z","iopub.execute_input":"2021-11-10T11:01:45.515315Z","iopub.status.idle":"2021-11-10T11:01:45.523645Z","shell.execute_reply.started":"2021-11-10T11:01:45.515279Z","shell.execute_reply":"2021-11-10T11:01:45.522859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_1","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:01:47.175008Z","iopub.execute_input":"2021-11-10T11:01:47.17537Z","iopub.status.idle":"2021-11-10T11:01:47.194007Z","shell.execute_reply.started":"2021-11-10T11:01:47.175334Z","shell.execute_reply":"2021-11-10T11:01:47.193353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_1.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:01:52.594928Z","iopub.execute_input":"2021-11-10T11:01:52.59599Z","iopub.status.idle":"2021-11-10T11:01:52.606318Z","shell.execute_reply.started":"2021-11-10T11:01:52.595942Z","shell.execute_reply":"2021-11-10T11:01:52.605215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_2=pd.read_csv('./items.csv')\ndf_2","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:01:54.797116Z","iopub.execute_input":"2021-11-10T11:01:54.797955Z","iopub.status.idle":"2021-11-10T11:01:54.825173Z","shell.execute_reply.started":"2021-11-10T11:01:54.797888Z","shell.execute_reply":"2021-11-10T11:01:54.824214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_2.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:01:58.047796Z","iopub.execute_input":"2021-11-10T11:01:58.048159Z","iopub.status.idle":"2021-11-10T11:01:58.060777Z","shell.execute_reply.started":"2021-11-10T11:01:58.04811Z","shell.execute_reply":"2021-11-10T11:01:58.059602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_3=pd.read_csv('./oil.csv')\ndf_3","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:01:59.959572Z","iopub.execute_input":"2021-11-10T11:01:59.960816Z","iopub.status.idle":"2021-11-10T11:01:59.978906Z","shell.execute_reply.started":"2021-11-10T11:01:59.960737Z","shell.execute_reply":"2021-11-10T11:01:59.977884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_3.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:02:03.757739Z","iopub.execute_input":"2021-11-10T11:02:03.75817Z","iopub.status.idle":"2021-11-10T11:02:03.770004Z","shell.execute_reply.started":"2021-11-10T11:02:03.758105Z","shell.execute_reply":"2021-11-10T11:02:03.768798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_4=pd.read_csv('./holidays_events.csv')\ndf_4","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:02:05.469166Z","iopub.execute_input":"2021-11-10T11:02:05.470057Z","iopub.status.idle":"2021-11-10T11:02:05.494293Z","shell.execute_reply.started":"2021-11-10T11:02:05.470004Z","shell.execute_reply":"2021-11-10T11:02:05.493209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_4.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:02:09.859217Z","iopub.execute_input":"2021-11-10T11:02:09.859532Z","iopub.status.idle":"2021-11-10T11:02:09.870371Z","shell.execute_reply.started":"2021-11-10T11:02:09.859501Z","shell.execute_reply":"2021-11-10T11:02:09.869222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_5=pd.read_csv('./transactions.csv')\ndf_5","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:02:11.723563Z","iopub.execute_input":"2021-11-10T11:02:11.724032Z","iopub.status.idle":"2021-11-10T11:02:11.78718Z","shell.execute_reply.started":"2021-11-10T11:02:11.723982Z","shell.execute_reply":"2021-11-10T11:02:11.786168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_5.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:02:13.803715Z","iopub.execute_input":"2021-11-10T11:02:13.804079Z","iopub.status.idle":"2021-11-10T11:02:13.824677Z","shell.execute_reply.started":"2021-11-10T11:02:13.804042Z","shell.execute_reply":"2021-11-10T11:02:13.823538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.dtypes","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:02:15.910812Z","iopub.execute_input":"2021-11-10T11:02:15.911415Z","iopub.status.idle":"2021-11-10T11:02:15.919419Z","shell.execute_reply.started":"2021-11-10T11:02:15.911374Z","shell.execute_reply":"2021-11-10T11:02:15.918458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['date']=pd.to_datetime(df['date'])\ndf.dtypes","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:02:18.767757Z","iopub.execute_input":"2021-11-10T11:02:18.768323Z","iopub.status.idle":"2021-11-10T11:02:42.842176Z","shell.execute_reply.started":"2021-11-10T11:02:18.768268Z","shell.execute_reply":"2021-11-10T11:02:42.841089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_1.dtypes","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:02:42.844232Z","iopub.execute_input":"2021-11-10T11:02:42.844475Z","iopub.status.idle":"2021-11-10T11:02:42.852392Z","shell.execute_reply.started":"2021-11-10T11:02:42.844448Z","shell.execute_reply":"2021-11-10T11:02:42.851236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_2.dtypes","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:02:42.853767Z","iopub.execute_input":"2021-11-10T11:02:42.854072Z","iopub.status.idle":"2021-11-10T11:02:42.869225Z","shell.execute_reply.started":"2021-11-10T11:02:42.854038Z","shell.execute_reply":"2021-11-10T11:02:42.868019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_3.dtypes","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:02:42.871789Z","iopub.execute_input":"2021-11-10T11:02:42.872214Z","iopub.status.idle":"2021-11-10T11:02:42.882109Z","shell.execute_reply.started":"2021-11-10T11:02:42.872162Z","shell.execute_reply":"2021-11-10T11:02:42.881235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_3['date']=pd.to_datetime(df_3['date'])\ndf_3.dtypes","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:02:53.159204Z","iopub.execute_input":"2021-11-10T11:02:53.160317Z","iopub.status.idle":"2021-11-10T11:02:53.171866Z","shell.execute_reply.started":"2021-11-10T11:02:53.160268Z","shell.execute_reply":"2021-11-10T11:02:53.170629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_4.dtypes","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:02:56.00179Z","iopub.execute_input":"2021-11-10T11:02:56.002131Z","iopub.status.idle":"2021-11-10T11:02:56.014359Z","shell.execute_reply.started":"2021-11-10T11:02:56.002098Z","shell.execute_reply":"2021-11-10T11:02:56.01334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_4['date']=pd.to_datetime(df_4['date'])\ndf_4.dtypes","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:02:58.133951Z","iopub.execute_input":"2021-11-10T11:02:58.134317Z","iopub.status.idle":"2021-11-10T11:02:58.145345Z","shell.execute_reply.started":"2021-11-10T11:02:58.134281Z","shell.execute_reply":"2021-11-10T11:02:58.144347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_5.dtypes","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:03:00.512193Z","iopub.execute_input":"2021-11-10T11:03:00.512516Z","iopub.status.idle":"2021-11-10T11:03:00.520881Z","shell.execute_reply.started":"2021-11-10T11:03:00.512483Z","shell.execute_reply":"2021-11-10T11:03:00.520214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_5['date']=pd.to_datetime(df_5['date'])\ndf_5.dtypes","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:03:01.991245Z","iopub.execute_input":"2021-11-10T11:03:01.991612Z","iopub.status.idle":"2021-11-10T11:03:02.018127Z","shell.execute_reply.started":"2021-11-10T11:03:01.991575Z","shell.execute_reply":"2021-11-10T11:03:02.017431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nnumbers = df_1[\"city\"].value_counts()\npaths = df_1[\"city\"].value_counts().keys()\nplt.title(\"City \")\nplt.ylabel(\"Different types of cities\")\nplt.xlabel(\"Count\")\nplt.barh(paths, numbers)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:03:03.971594Z","iopub.execute_input":"2021-11-10T11:03:03.972366Z","iopub.status.idle":"2021-11-10T11:03:04.378655Z","shell.execute_reply.started":"2021-11-10T11:03:03.972314Z","shell.execute_reply":"2021-11-10T11:03:04.377528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nnumbers = df_1[\"state\"].value_counts()\npaths = df_1[\"state\"].value_counts().keys()\nplt.title(\"State \")\nplt.ylabel(\"Different types of states\")\nplt.xlabel(\"Count\")\nplt.barh(paths, numbers)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:03:07.275855Z","iopub.execute_input":"2021-11-10T11:03:07.276171Z","iopub.status.idle":"2021-11-10T11:03:07.557599Z","shell.execute_reply.started":"2021-11-10T11:03:07.276125Z","shell.execute_reply":"2021-11-10T11:03:07.556662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nnumbers = df_1[\"type\"].value_counts()\npaths = df_1[\"type\"].value_counts().keys()\nplt.title(\"Type \")\nplt.ylabel(\"Different types\")\nplt.xlabel(\"Count\")\nplt.bar(paths, numbers)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:03:09.47013Z","iopub.execute_input":"2021-11-10T11:03:09.470464Z","iopub.status.idle":"2021-11-10T11:03:09.677288Z","shell.execute_reply.started":"2021-11-10T11:03:09.470431Z","shell.execute_reply":"2021-11-10T11:03:09.676238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LinearRegression\nfrom scipy.special import boxcox1p\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:03:12.310786Z","iopub.execute_input":"2021-11-10T11:03:12.312021Z","iopub.status.idle":"2021-11-10T11:03:13.952423Z","shell.execute_reply.started":"2021-11-10T11:03:12.311956Z","shell.execute_reply":"2021-11-10T11:03:13.951272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = df[['date']]\ny=df['unit_sales']\n# Creating a linear regression model\nmodel = LinearRegression()\n\n# Fitting the model to the data i.e. building the model\nmodel.fit(X, y)\n\n# Fetching intercept (b0) and coefficient (b1)\nprint(\"Intercept:\", model.intercept_)\nprint(\"Coefficients:\",model.coef_)","metadata":{"execution":{"iopub.status.busy":"2021-11-10T11:04:24.237774Z","iopub.execute_input":"2021-11-10T11:04:24.238118Z","iopub.status.idle":"2021-11-10T11:04:34.505457Z","shell.execute_reply.started":"2021-11-10T11:04:24.238084Z","shell.execute_reply":"2021-11-10T11:04:34.504215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.scatter(X, y)\nplt.plot(X, 18.896086811682437 +(-7.16977587e-18) * X_test, 'r')\nplt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}