{"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-12T13:03:44.949378Z","iopub.execute_input":"2022-07-12T13:03:44.950040Z","iopub.status.idle":"2022-07-12T13:03:44.989685Z","shell.execute_reply.started":"2022-07-12T13:03:44.949956Z","shell.execute_reply":"2022-07-12T13:03:44.988547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install chart_studio\n!pip install cufflinks","metadata":{"execution":{"iopub.status.busy":"2022-07-12T13:04:23.406861Z","iopub.execute_input":"2022-07-12T13:04:23.407216Z","iopub.status.idle":"2022-07-12T13:04:48.287875Z","shell.execute_reply.started":"2022-07-12T13:04:23.407187Z","shell.execute_reply":"2022-07-12T13:04:48.286401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import chart_studio.plotly as py\nimport plotly.express as px\nimport seaborn as sns\nimport cufflinks as cf\nimport plotly.graph_objects as go\nfrom plotly.offline import download_plotlyjs,init_notebook_mode,plot,iplot\ninit_notebook_mode(connected = True)\ncf.go_offline()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T13:05:04.553695Z","iopub.execute_input":"2022-07-12T13:05:04.554131Z","iopub.status.idle":"2022-07-12T13:05:07.762449Z","shell.execute_reply.started":"2022-07-12T13:05:04.554091Z","shell.execute_reply":"2022-07-12T13:05:07.761434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***Reading the data***","metadata":{}},{"cell_type":"code","source":"holidays_events = pd.read_csv('../input/store-sales-time-series-forecasting/holidays_events.csv')\ntransaction = pd.read_csv('../input/store-sales-time-series-forecasting/transactions.csv')\noil = pd.read_csv('../input/store-sales-time-series-forecasting/oil.csv')\nstores = pd.read_csv('../input/store-sales-time-series-forecasting/stores.csv')\ntrain = pd.read_csv('../input/store-sales-time-series-forecasting/train.csv')\ntest = pd.read_csv('../input/store-sales-time-series-forecasting/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:38:32.559884Z","iopub.execute_input":"2022-07-12T14:38:32.560251Z","iopub.status.idle":"2022-07-12T14:38:34.683169Z","shell.execute_reply.started":"2022-07-12T14:38:32.560208Z","shell.execute_reply":"2022-07-12T14:38:34.682268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"holidays_events.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:38:34.684415Z","iopub.execute_input":"2022-07-12T14:38:34.684712Z","iopub.status.idle":"2022-07-12T14:38:34.694355Z","shell.execute_reply.started":"2022-07-12T14:38:34.684684Z","shell.execute_reply":"2022-07-12T14:38:34.693262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"oil.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:38:34.697828Z","iopub.execute_input":"2022-07-12T14:38:34.698307Z","iopub.status.idle":"2022-07-12T14:38:34.707262Z","shell.execute_reply.started":"2022-07-12T14:38:34.698264Z","shell.execute_reply":"2022-07-12T14:38:34.706293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"stores.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:38:34.708317Z","iopub.execute_input":"2022-07-12T14:38:34.709119Z","iopub.status.idle":"2022-07-12T14:38:34.722494Z","shell.execute_reply.started":"2022-07-12T14:38:34.709086Z","shell.execute_reply":"2022-07-12T14:38:34.721116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transaction.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:38:34.724195Z","iopub.execute_input":"2022-07-12T14:38:34.724781Z","iopub.status.idle":"2022-07-12T14:38:34.743252Z","shell.execute_reply.started":"2022-07-12T14:38:34.724687Z","shell.execute_reply":"2022-07-12T14:38:34.742535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:38:34.744238Z","iopub.execute_input":"2022-07-12T14:38:34.744876Z","iopub.status.idle":"2022-07-12T14:38:35.393242Z","shell.execute_reply.started":"2022-07-12T14:38:34.744846Z","shell.execute_reply":"2022-07-12T14:38:35.392262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"oil['dcoilwtico'] = oil['dcoilwtico'].fillna(oil['dcoilwtico'].mean())","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:38:35.394503Z","iopub.execute_input":"2022-07-12T14:38:35.395173Z","iopub.status.idle":"2022-07-12T14:38:35.401602Z","shell.execute_reply.started":"2022-07-12T14:38:35.395140Z","shell.execute_reply":"2022-07-12T14:38:35.400487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"stores.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:38:35.404194Z","iopub.execute_input":"2022-07-12T14:38:35.404625Z","iopub.status.idle":"2022-07-12T14:38:35.426813Z","shell.execute_reply.started":"2022-07-12T14:38:35.404586Z","shell.execute_reply":"2022-07-12T14:38:35.425765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"oil.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:38:35.431877Z","iopub.execute_input":"2022-07-12T14:38:35.433254Z","iopub.status.idle":"2022-07-12T14:38:35.443827Z","shell.execute_reply.started":"2022-07-12T14:38:35.433181Z","shell.execute_reply":"2022-07-12T14:38:35.442769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:38:35.445064Z","iopub.execute_input":"2022-07-12T14:38:35.445702Z","iopub.status.idle":"2022-07-12T14:38:35.458225Z","shell.execute_reply.started":"2022-07-12T14:38:35.445662Z","shell.execute_reply":"2022-07-12T14:38:35.457473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"holidays_events.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:38:35.459283Z","iopub.execute_input":"2022-07-12T14:38:35.460279Z","iopub.status.idle":"2022-07-12T14:38:35.475905Z","shell.execute_reply.started":"2022-07-12T14:38:35.460238Z","shell.execute_reply":"2022-07-12T14:38:35.475119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = pd.merge(train,stores,on = 'store_nbr')\ndataset","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:38:35.477114Z","iopub.execute_input":"2022-07-12T14:38:35.477812Z","iopub.status.idle":"2022-07-12T14:38:36.081042Z","shell.execute_reply.started":"2022-07-12T14:38:35.477779Z","shell.execute_reply":"2022-07-12T14:38:36.079959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"holidays_events = holidays_events.drop(columns = ['description','locale'])\ndataset = dataset.merge(holidays_events,how='left', left_on='date', right_on='date')\ndataset","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:38:36.082427Z","iopub.execute_input":"2022-07-12T14:38:36.082749Z","iopub.status.idle":"2022-07-12T14:38:37.025773Z","shell.execute_reply.started":"2022-07-12T14:38:36.082720Z","shell.execute_reply":"2022-07-12T14:38:37.024584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = dataset.merge(oil,how = 'left',left_on = 'date',right_on = 'date')\ndataset","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:38:37.027256Z","iopub.execute_input":"2022-07-12T14:38:37.027677Z","iopub.status.idle":"2022-07-12T14:38:38.008764Z","shell.execute_reply.started":"2022-07-12T14:38:37.027643Z","shell.execute_reply":"2022-07-12T14:38:38.007691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset.rename(columns={'type_y':'day_type'},inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:38:51.052885Z","iopub.execute_input":"2022-07-12T14:38:51.053284Z","iopub.status.idle":"2022-07-12T14:38:51.059377Z","shell.execute_reply.started":"2022-07-12T14:38:51.053252Z","shell.execute_reply":"2022-07-12T14:38:51.058380Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset['day_type'] = dataset['day_type'].fillna('Normal')\ndataset","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:38:54.048093Z","iopub.execute_input":"2022-07-12T14:38:54.048456Z","iopub.status.idle":"2022-07-12T14:38:54.468468Z","shell.execute_reply.started":"2022-07-12T14:38:54.048427Z","shell.execute_reply":"2022-07-12T14:38:54.467344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import datetime as dt\ndataset['date'] = pd.to_datetime(dataset['date']) \ndataset['day'] = dataset['date'].dt.day_name()\ndataset['month'] = dataset['date'].dt.month\ndataset['year'] = dataset['date'].dt.year\ndataset['day_of_week'] = dataset['date'].dt.dayofweek\ndataset['day_of_week']\ndataset","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:39:08.318444Z","iopub.execute_input":"2022-07-12T14:39:08.318867Z","iopub.status.idle":"2022-07-12T14:39:10.532879Z","shell.execute_reply.started":"2022-07-12T14:39:08.318831Z","shell.execute_reply":"2022-07-12T14:39:10.531557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:39:25.992755Z","iopub.execute_input":"2022-07-12T14:39:25.993477Z","iopub.status.idle":"2022-07-12T14:39:28.279025Z","shell.execute_reply.started":"2022-07-12T14:39:25.993439Z","shell.execute_reply":"2022-07-12T14:39:28.277828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset.drop(columns = ['locale_name','transferred','dcoilwtico'],inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:39:28.281037Z","iopub.execute_input":"2022-07-12T14:39:28.281377Z","iopub.status.idle":"2022-07-12T14:39:29.609235Z","shell.execute_reply.started":"2022-07-12T14:39:28.281346Z","shell.execute_reply":"2022-07-12T14:39:29.608182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Get the apprioperate sample size of the dataset","metadata":{}},{"cell_type":"code","source":"import scipy.stats as st\nfrom math import ceil\n\ndef sample_size(N,confidence_level,margin,proportion):\n    z = st.norm.ppf(1-(1 - confidence_level) / 2)\n    n0 = z**2 * proportion * (1 - proportion) / margin**2\n    n = n0 / (1 + (n0 - 1) / N)\n    n = ceil(n)\n    return n","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:39:33.128792Z","iopub.execute_input":"2022-07-12T14:39:33.129179Z","iopub.status.idle":"2022-07-12T14:39:33.135960Z","shell.execute_reply.started":"2022-07-12T14:39:33.129148Z","shell.execute_reply":"2022-07-12T14:39:33.134806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sampleSize = sample_size(len(dataset),0.95,0.05,0.5) \nsampleSize","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:39:34.267996Z","iopub.execute_input":"2022-07-12T14:39:34.269055Z","iopub.status.idle":"2022-07-12T14:39:34.276454Z","shell.execute_reply.started":"2022-07-12T14:39:34.269015Z","shell.execute_reply":"2022-07-12T14:39:34.275543Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sampleData = dataset.sample(sampleSize)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:39:35.760354Z","iopub.execute_input":"2022-07-12T14:39:35.761491Z","iopub.status.idle":"2022-07-12T14:39:35.890341Z","shell.execute_reply.started":"2022-07-12T14:39:35.761444Z","shell.execute_reply":"2022-07-12T14:39:35.889032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:39:39.376742Z","iopub.execute_input":"2022-07-12T14:39:39.377151Z","iopub.status.idle":"2022-07-12T14:39:39.381931Z","shell.execute_reply.started":"2022-07-12T14:39:39.377116Z","shell.execute_reply":"2022-07-12T14:39:39.380928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(rc = {'figure.figsize':(16,8)})\nax = sns.barplot('family','sales',data = sampleData)\nplt.xticks(rotation=90)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:39:39.970841Z","iopub.execute_input":"2022-07-12T14:39:39.971210Z","iopub.status.idle":"2022-07-12T14:39:41.503049Z","shell.execute_reply.started":"2022-07-12T14:39:39.971181Z","shell.execute_reply":"2022-07-12T14:39:41.501942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(rc = {'figure.figsize':(22,15)})\nax = sns.boxplot(x=\"city\", y=\"sales\", data=sampleData)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:39:43.322678Z","iopub.execute_input":"2022-07-12T14:39:43.323048Z","iopub.status.idle":"2022-07-12T14:39:43.923724Z","shell.execute_reply.started":"2022-07-12T14:39:43.323019Z","shell.execute_reply":"2022-07-12T14:39:43.922328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(dataset[(dataset['city']=='Quito') & (dataset['sales']>2000)])","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:39:47.873630Z","iopub.execute_input":"2022-07-12T14:39:47.874147Z","iopub.status.idle":"2022-07-12T14:39:48.368323Z","shell.execute_reply.started":"2022-07-12T14:39:47.874104Z","shell.execute_reply":"2022-07-12T14:39:48.367209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(dataset[(dataset['city']=='Guayaquil') & (dataset['sales']>2000)])","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:39:48.735698Z","iopub.execute_input":"2022-07-12T14:39:48.736076Z","iopub.status.idle":"2022-07-12T14:39:49.206134Z","shell.execute_reply.started":"2022-07-12T14:39:48.736046Z","shell.execute_reply":"2022-07-12T14:39:49.205285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"px.bar(sampleData,x = 'type_x',y = 'sales',color = 'day_type')","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:39:50.265382Z","iopub.execute_input":"2022-07-12T14:39:50.265784Z","iopub.status.idle":"2022-07-12T14:39:50.370619Z","shell.execute_reply.started":"2022-07-12T14:39:50.265752Z","shell.execute_reply":"2022-07-12T14:39:50.369502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"px.bar(sampleData,x = 'family',y = 'sales',color = 'day_type')","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:39:53.295403Z","iopub.execute_input":"2022-07-12T14:39:53.296564Z","iopub.status.idle":"2022-07-12T14:39:53.400715Z","shell.execute_reply.started":"2022-07-12T14:39:53.296523Z","shell.execute_reply":"2022-07-12T14:39:53.399941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"px.pie(sampleData,values = 'sales',names = 'day_type',title = 'Sales and Day Type',hover_name = 'day_type')\n","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:39:58.211353Z","iopub.execute_input":"2022-07-12T14:39:58.212053Z","iopub.status.idle":"2022-07-12T14:39:58.274294Z","shell.execute_reply.started":"2022-07-12T14:39:58.212017Z","shell.execute_reply":"2022-07-12T14:39:58.273513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"px.pie(sampleData,values = 'sales',names = 'type_x',title = 'Sales and Type',hover_name = 'type_x')\n","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:40:03.283061Z","iopub.execute_input":"2022-07-12T14:40:03.283717Z","iopub.status.idle":"2022-07-12T14:40:03.344060Z","shell.execute_reply.started":"2022-07-12T14:40:03.283682Z","shell.execute_reply":"2022-07-12T14:40:03.343280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"px.bar(sampleData,x = 'day',y = 'sales',color = 'type_x',title = 'Day vs Sales')","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:40:07.911802Z","iopub.execute_input":"2022-07-12T14:40:07.912685Z","iopub.status.idle":"2022-07-12T14:40:08.008602Z","shell.execute_reply.started":"2022-07-12T14:40:07.912642Z","shell.execute_reply":"2022-07-12T14:40:08.007499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"px.bar(sampleData,x = 'month',y = 'sales',color = 'day_type')","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:40:12.028357Z","iopub.execute_input":"2022-07-12T14:40:12.028827Z","iopub.status.idle":"2022-07-12T14:40:12.128595Z","shell.execute_reply.started":"2022-07-12T14:40:12.028788Z","shell.execute_reply":"2022-07-12T14:40:12.127495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"px.bar(sampleData,x = 'month',y = 'sales',color = 'family')","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:40:16.917991Z","iopub.execute_input":"2022-07-12T14:40:16.918817Z","iopub.status.idle":"2022-07-12T14:40:17.129943Z","shell.execute_reply.started":"2022-07-12T14:40:16.918781Z","shell.execute_reply":"2022-07-12T14:40:17.128771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.bar(sampleData,x = 'store_nbr',y = 'sales',title = 'Stores vs Sales',color = 'type_x')\nfig.update_layout(uniformtext_minsize = 8)\nfig","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:40:23.967185Z","iopub.execute_input":"2022-07-12T14:40:23.967598Z","iopub.status.idle":"2022-07-12T14:40:24.060708Z","shell.execute_reply.started":"2022-07-12T14:40:23.967565Z","shell.execute_reply":"2022-07-12T14:40:24.059503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***This graph shows sales of each city over years***","metadata":{}},{"cell_type":"code","source":"px.density_heatmap(sampleData,x = 'city',y = 'year',z = 'sales',color_continuous_scale = 'Viridis')","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:40:30.837904Z","iopub.execute_input":"2022-07-12T14:40:30.838311Z","iopub.status.idle":"2022-07-12T14:40:30.912312Z","shell.execute_reply.started":"2022-07-12T14:40:30.838277Z","shell.execute_reply":"2022-07-12T14:40:30.911195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"px.bar(sampleData,x = 'cluster',y='sales',color = 'day_type',range_y = [0,50000])","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:40:34.921722Z","iopub.execute_input":"2022-07-12T14:40:34.922098Z","iopub.status.idle":"2022-07-12T14:40:35.022845Z","shell.execute_reply.started":"2022-07-12T14:40:34.922066Z","shell.execute_reply":"2022-07-12T14:40:35.021585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = dataset[['store_nbr','onpromotion','family','month','day','type_x','day_type','cluster']]\nX","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:42:29.332965Z","iopub.execute_input":"2022-07-12T14:42:29.334032Z","iopub.status.idle":"2022-07-12T14:42:29.531067Z","shell.execute_reply.started":"2022-07-12T14:42:29.333982Z","shell.execute_reply":"2022-07-12T14:42:29.530051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nfrom sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:43:02.007133Z","iopub.execute_input":"2022-07-12T14:43:02.007640Z","iopub.status.idle":"2022-07-12T14:43:02.062268Z","shell.execute_reply.started":"2022-07-12T14:43:02.007602Z","shell.execute_reply":"2022-07-12T14:43:02.061281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le = LabelEncoder()\nX['day'] = le.fit_transform(X['day'])\nX['family'] = le.fit_transform(X['family'])\nX['type_x'] = le.fit_transform(X['type_x'])\nX","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:45:51.971791Z","iopub.execute_input":"2022-07-12T14:45:51.972177Z","iopub.status.idle":"2022-07-12T14:45:55.004335Z","shell.execute_reply.started":"2022-07-12T14:45:51.972130Z","shell.execute_reply":"2022-07-12T14:45:55.003258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X['day_type'] = le.fit_transform(X['day_type'])\nX","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:46:57.449950Z","iopub.execute_input":"2022-07-12T14:46:57.450334Z","iopub.status.idle":"2022-07-12T14:46:58.344484Z","shell.execute_reply.started":"2022-07-12T14:46:57.450303Z","shell.execute_reply":"2022-07-12T14:46:58.343419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = dataset['sales']\ny","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:48:28.428493Z","iopub.execute_input":"2022-07-12T14:48:28.428889Z","iopub.status.idle":"2022-07-12T14:48:28.438061Z","shell.execute_reply.started":"2022-07-12T14:48:28.428859Z","shell.execute_reply":"2022-07-12T14:48:28.436979Z"},"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)\nX_train.shape,X_test.shape,y_train.shape,y_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:50:08.240820Z","iopub.execute_input":"2022-07-12T14:50:08.241244Z","iopub.status.idle":"2022-07-12T14:50:08.971571Z","shell.execute_reply.started":"2022-07-12T14:50:08.241190Z","shell.execute_reply":"2022-07-12T14:50:08.970527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestRegressor\nRFR = RandomForestRegressor(n_estimators = 10)\nRFR.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:51:16.329107Z","iopub.execute_input":"2022-07-12T14:51:16.330038Z","iopub.status.idle":"2022-07-12T14:52:41.733328Z","shell.execute_reply.started":"2022-07-12T14:51:16.329997Z","shell.execute_reply":"2022-07-12T14:52:41.732459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"RFR.score(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:53:02.809585Z","iopub.execute_input":"2022-07-12T14:53:02.809965Z","iopub.status.idle":"2022-07-12T14:53:23.191484Z","shell.execute_reply.started":"2022-07-12T14:53:02.809935Z","shell.execute_reply":"2022-07-12T14:53:23.190215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"RFR.score(X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T14:53:46.757093Z","iopub.execute_input":"2022-07-12T14:53:46.757495Z","iopub.status.idle":"2022-07-12T14:53:51.894380Z","shell.execute_reply.started":"2022-07-12T14:53:46.757463Z","shell.execute_reply":"2022-07-12T14:53:51.893269Z"},"trusted":true},"execution_count":null,"outputs":[]}]}