{"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":"import pandas as pd\nimport numpy as np\nfrom sklearn import linear_model\nfrom sklearn.metrics import accuracy_score\nimport matplotlib.pyplot as plt \nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import r2_score, mean_absolute_error, mean_squared_error \nfrom sklearn.svm import SVR\nimport statsmodels.api as sm\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.preprocessing import PolynomialFeatures\nfrom sklearn.preprocessing import LabelEncoder\nfrom sklearn.preprocessing import LabelBinarizer\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.model_selection import cross_val_score\nimport datetime as dt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-01-11T13:59:59.172297Z","iopub.execute_input":"2022-01-11T13:59:59.172779Z","iopub.status.idle":"2022-01-11T13:59:59.863601Z","shell.execute_reply.started":"2022-01-11T13:59:59.172732Z","shell.execute_reply":"2022-01-11T13:59:59.862822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df=pd.read_csv(\"../input/tabular-playground-series-jan-2022/train.csv\")\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-11T13:56:47.944752Z","iopub.execute_input":"2022-01-11T13:56:47.945027Z","iopub.status.idle":"2022-01-11T13:56:48.016459Z","shell.execute_reply.started":"2022-01-11T13:56:47.944996Z","shell.execute_reply":"2022-01-11T13:56:48.015736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df= train_df.drop(['row_id'] , axis = 1)","metadata":{"execution":{"iopub.status.busy":"2022-01-11T13:56:52.492849Z","iopub.execute_input":"2022-01-11T13:56:52.493699Z","iopub.status.idle":"2022-01-11T13:56:52.505443Z","shell.execute_reply.started":"2022-01-11T13:56:52.493659Z","shell.execute_reply":"2022-01-11T13:56:52.504813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df","metadata":{"execution":{"iopub.status.busy":"2022-01-11T13:56:57.216684Z","iopub.execute_input":"2022-01-11T13:56:57.216982Z","iopub.status.idle":"2022-01-11T13:56:57.232937Z","shell.execute_reply.started":"2022-01-11T13:56:57.216951Z","shell.execute_reply":"2022-01-11T13:56:57.231873Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df=pd.read_csv(\"../input/tabular-playground-series-jan-2022/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-01-11T13:56:59.752787Z","iopub.execute_input":"2022-01-11T13:56:59.753050Z","iopub.status.idle":"2022-01-11T13:56:59.776754Z","shell.execute_reply.started":"2022-01-11T13:56:59.753022Z","shell.execute_reply":"2022-01-11T13:56:59.776117Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-11T13:57:01.677765Z","iopub.execute_input":"2022-01-11T13:57:01.678280Z","iopub.status.idle":"2022-01-11T13:57:01.690858Z","shell.execute_reply.started":"2022-01-11T13:57:01.678244Z","shell.execute_reply":"2022-01-11T13:57:01.690060Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df=test_df.drop(['row_id'], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-01-11T13:57:04.429403Z","iopub.execute_input":"2022-01-11T13:57:04.429672Z","iopub.status.idle":"2022-01-11T13:57:04.434929Z","shell.execute_reply.started":"2022-01-11T13:57:04.429644Z","shell.execute_reply":"2022-01-11T13:57:04.433904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{"execution":{"iopub.status.busy":"2022-01-11T13:57:06.932126Z","iopub.execute_input":"2022-01-11T13:57:06.932398Z","iopub.status.idle":"2022-01-11T13:57:06.947975Z","shell.execute_reply.started":"2022-01-11T13:57:06.932370Z","shell.execute_reply":"2022-01-11T13:57:06.947128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X=train_df.drop(['num_sold'], axis=1)\nX","metadata":{"execution":{"iopub.status.busy":"2022-01-11T13:57:09.902236Z","iopub.execute_input":"2022-01-11T13:57:09.902993Z","iopub.status.idle":"2022-01-11T13:57:09.919787Z","shell.execute_reply.started":"2022-01-11T13:57:09.902955Z","shell.execute_reply":"2022-01-11T13:57:09.919168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y=train_df['num_sold']\nY","metadata":{"execution":{"iopub.status.busy":"2022-01-11T13:57:12.376880Z","iopub.execute_input":"2022-01-11T13:57:12.377634Z","iopub.status.idle":"2022-01-11T13:57:12.393141Z","shell.execute_reply.started":"2022-01-11T13:57:12.377600Z","shell.execute_reply":"2022-01-11T13:57:12.391239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X['date']=pd.to_datetime(X['date'])\nX.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-11T13:57:16.304074Z","iopub.execute_input":"2022-01-11T13:57:16.304525Z","iopub.status.idle":"2022-01-11T13:57:16.341907Z","shell.execute_reply.started":"2022-01-11T13:57:16.304475Z","shell.execute_reply":"2022-01-11T13:57:16.341165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X['year']=X['date'].dt.year\nX['month']=X['date'].dt.month\nX['day']=X['date'].dt.day\nX\n#df['year'] = df['date'].dt.year","metadata":{"execution":{"iopub.status.busy":"2022-01-11T13:57:18.485108Z","iopub.execute_input":"2022-01-11T13:57:18.485685Z","iopub.status.idle":"2022-01-11T13:57:18.513692Z","shell.execute_reply.started":"2022-01-11T13:57:18.485633Z","shell.execute_reply":"2022-01-11T13:57:18.512837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#X['date']=pd.to_datetime(X['date'])","metadata":{"execution":{"iopub.status.busy":"2022-01-05T19:40:33.053346Z","iopub.execute_input":"2022-01-05T19:40:33.05378Z","iopub.status.idle":"2022-01-05T19:40:33.059275Z","shell.execute_reply.started":"2022-01-05T19:40:33.053733Z","shell.execute_reply":"2022-01-05T19:40:33.058481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#X['date']=X['date'].map(dt.datetime.toordinal)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T22:58:27.3879Z","iopub.execute_input":"2022-01-04T22:58:27.388201Z","iopub.status.idle":"2022-01-04T22:58:27.540616Z","shell.execute_reply.started":"2022-01-04T22:58:27.38816Z","shell.execute_reply":"2022-01-04T22:58:27.539458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#X.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T22:58:55.500384Z","iopub.execute_input":"2022-01-04T22:58:55.500686Z","iopub.status.idle":"2022-01-04T22:58:55.522742Z","shell.execute_reply.started":"2022-01-04T22:58:55.500653Z","shell.execute_reply":"2022-01-04T22:58:55.52177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Encoding Labels","metadata":{}},{"cell_type":"code","source":"#lb_encoder= LabelEncoder()\n#X['country_enc']=lb_encoder.fit_transform(X['country'])\n#X['store_enc']=lb_encoder.fit_transform(X['store'])\n#X['product_enc']=lb_encoder.fit_transform(X['product'])","metadata":{"execution":{"iopub.status.busy":"2022-01-05T16:20:46.380434Z","iopub.execute_input":"2022-01-05T16:20:46.380763Z","iopub.status.idle":"2022-01-05T16:20:46.417319Z","shell.execute_reply.started":"2022-01-05T16:20:46.380728Z","shell.execute_reply":"2022-01-05T16:20:46.416675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#X=X.drop(['country','store','product'], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T16:10:54.594978Z","iopub.execute_input":"2022-01-04T16:10:54.595853Z","iopub.status.idle":"2022-01-04T16:10:54.603324Z","shell.execute_reply.started":"2022-01-04T16:10:54.595802Z","shell.execute_reply":"2022-01-04T16:10:54.602585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## One Hot encoding","metadata":{}},{"cell_type":"code","source":"X.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-11T13:57:27.204863Z","iopub.execute_input":"2022-01-11T13:57:27.205442Z","iopub.status.idle":"2022-01-11T13:57:27.227895Z","shell.execute_reply.started":"2022-01-11T13:57:27.205391Z","shell.execute_reply":"2022-01-11T13:57:27.226844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#lb_binary = LabelBinarizer()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T22:51:03.435732Z","iopub.execute_input":"2022-01-04T22:51:03.43618Z","iopub.status.idle":"2022-01-04T22:51:03.440158Z","shell.execute_reply.started":"2022-01-04T22:51:03.436148Z","shell.execute_reply":"2022-01-04T22:51:03.439109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#X_copy['country']= lb_binary.fit_transform(X['country'])","metadata":{"execution":{"iopub.status.busy":"2022-01-04T22:49:27.389631Z","iopub.execute_input":"2022-01-04T22:49:27.389892Z","iopub.status.idle":"2022-01-04T22:49:27.52088Z","shell.execute_reply.started":"2022-01-04T22:49:27.389863Z","shell.execute_reply":"2022-01-04T22:49:27.520092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X","metadata":{"execution":{"iopub.status.busy":"2022-01-05T19:40:54.762041Z","iopub.execute_input":"2022-01-05T19:40:54.762362Z","iopub.status.idle":"2022-01-05T19:40:54.778396Z","shell.execute_reply.started":"2022-01-05T19:40:54.762325Z","shell.execute_reply":"2022-01-05T19:40:54.777762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X=pd.get_dummies(X, columns=['country'], prefix_sep= '_')\nX=pd.get_dummies(X, columns=['store'], prefix_sep= '_')\nX=pd.get_dummies(X, columns=['product'], prefix_sep= '_')\nX","metadata":{"execution":{"iopub.status.busy":"2022-01-11T13:57:33.133949Z","iopub.execute_input":"2022-01-11T13:57:33.134583Z","iopub.status.idle":"2022-01-11T13:57:33.175241Z","shell.execute_reply.started":"2022-01-11T13:57:33.134544Z","shell.execute_reply":"2022-01-11T13:57:33.174461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-11T13:57:36.748203Z","iopub.execute_input":"2022-01-11T13:57:36.748496Z","iopub.status.idle":"2022-01-11T13:57:36.765014Z","shell.execute_reply.started":"2022-01-11T13:57:36.748464Z","shell.execute_reply":"2022-01-11T13:57:36.764168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X=X.drop(['date'], axis=1)\nX","metadata":{"execution":{"iopub.status.busy":"2022-01-11T13:57:41.298226Z","iopub.execute_input":"2022-01-11T13:57:41.298893Z","iopub.status.idle":"2022-01-11T13:57:41.321570Z","shell.execute_reply.started":"2022-01-11T13:57:41.298849Z","shell.execute_reply":"2022-01-11T13:57:41.320863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-11T13:57:43.732288Z","iopub.execute_input":"2022-01-11T13:57:43.732541Z","iopub.status.idle":"2022-01-11T13:57:43.746282Z","shell.execute_reply.started":"2022-01-11T13:57:43.732513Z","shell.execute_reply":"2022-01-11T13:57:43.745690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#sc_X = StandardScaler()\n#sc_y = StandardScaler()\n#X = sc_X.fit_transform(X)\n#Y = sc_y.fit_transform(Y.values.reshape(-1,1))","metadata":{"execution":{"iopub.status.busy":"2022-01-07T00:13:09.453627Z","iopub.execute_input":"2022-01-07T00:13:09.454529Z","iopub.status.idle":"2022-01-07T00:13:09.476568Z","shell.execute_reply.started":"2022-01-07T00:13:09.454473Z","shell.execute_reply":"2022-01-07T00:13:09.475476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# adding the constant term\nX= sm.add_constant(X)","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:01:09.524410Z","iopub.execute_input":"2022-01-11T14:01:09.524688Z","iopub.status.idle":"2022-01-11T14:01:09.539819Z","shell.execute_reply.started":"2022-01-11T14:01:09.524661Z","shell.execute_reply":"2022-01-11T14:01:09.539217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:01:56.101915Z","iopub.execute_input":"2022-01-11T14:01:56.102664Z","iopub.status.idle":"2022-01-11T14:01:56.116009Z","shell.execute_reply.started":"2022-01-11T14:01:56.102625Z","shell.execute_reply":"2022-01-11T14:01:56.115058Z"},"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.3, random_state=1)","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:02:04.011562Z","iopub.execute_input":"2022-01-11T14:02:04.011954Z","iopub.status.idle":"2022-01-11T14:02:04.020748Z","shell.execute_reply.started":"2022-01-11T14:02:04.011924Z","shell.execute_reply":"2022-01-11T14:02:04.019965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#regressor = SVR(kernel = 'rbf')\n#regressor.fit(X, Y)","metadata":{"execution":{"iopub.status.busy":"2022-01-11T13:59:01.047906Z","iopub.execute_input":"2022-01-11T13:59:01.048303Z","iopub.status.idle":"2022-01-11T13:59:01.050856Z","shell.execute_reply.started":"2022-01-11T13:59:01.048275Z","shell.execute_reply":"2022-01-11T13:59:01.050268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#regressor.score(X,Y)","metadata":{"execution":{"iopub.status.busy":"2022-01-06T16:58:49.458014Z","iopub.execute_input":"2022-01-06T16:58:49.458308Z","iopub.status.idle":"2022-01-06T16:59:05.773702Z","shell.execute_reply.started":"2022-01-06T16:58:49.458272Z","shell.execute_reply":"2022-01-06T16:59:05.772791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#alphas = [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09]\n#model= linear_model.Ridge(alpha=0.005)\n#poly = PolynomialFeatures(degree=2, include_bias=False)\n#poly_xtrain = poly.fit_transform(x_train)","metadata":{"execution":{"iopub.status.busy":"2022-01-07T00:13:40.938417Z","iopub.execute_input":"2022-01-07T00:13:40.938781Z","iopub.status.idle":"2022-01-07T00:13:40.94398Z","shell.execute_reply.started":"2022-01-07T00:13:40.938743Z","shell.execute_reply":"2022-01-07T00:13:40.942876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#model=linear_model.Ridge(alpha=0.0000005)","metadata":{"execution":{"iopub.status.busy":"2022-01-05T19:44:49.887523Z","iopub.execute_input":"2022-01-05T19:44:49.888238Z","iopub.status.idle":"2022-01-05T19:44:49.893146Z","shell.execute_reply.started":"2022-01-05T19:44:49.888174Z","shell.execute_reply":"2022-01-05T19:44:49.892248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# performing the regression\n# and fitting the model\nOLSmodel = sm.OLS(y_train, x_train).fit()","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:03:10.559362Z","iopub.execute_input":"2022-01-11T14:03:10.559641Z","iopub.status.idle":"2022-01-11T14:03:10.589024Z","shell.execute_reply.started":"2022-01-11T14:03:10.559611Z","shell.execute_reply":"2022-01-11T14:03:10.588405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# printing the summary table\nprint(OLSmodel.summary())","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:03:19.664356Z","iopub.execute_input":"2022-01-11T14:03:19.664654Z","iopub.status.idle":"2022-01-11T14:03:19.692698Z","shell.execute_reply.started":"2022-01-11T14:03:19.664627Z","shell.execute_reply":"2022-01-11T14:03:19.691652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#model.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-01-07T00:13:51.922604Z","iopub.execute_input":"2022-01-07T00:13:51.923306Z","iopub.status.idle":"2022-01-07T00:13:51.963547Z","shell.execute_reply.started":"2022-01-07T00:13:51.923236Z","shell.execute_reply":"2022-01-07T00:13:51.962452Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#model.score(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:05:05.494321Z","iopub.execute_input":"2022-01-11T14:05:05.494990Z","iopub.status.idle":"2022-01-11T14:05:05.498191Z","shell.execute_reply.started":"2022-01-11T14:05:05.494953Z","shell.execute_reply":"2022-01-11T14:05:05.497596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#poly_xtest = poly.fit_transform(x_test)","metadata":{"execution":{"iopub.status.busy":"2022-01-05T16:27:06.189789Z","iopub.execute_input":"2022-01-05T16:27:06.190087Z","iopub.status.idle":"2022-01-05T16:27:06.199032Z","shell.execute_reply.started":"2022-01-05T16:27:06.190057Z","shell.execute_reply":"2022-01-05T16:27:06.198292Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Y_predicted=model.predict(x_test)\n#Y_predicted\n\nY_predicted=OLSmodel.predict(x_test)\nY_predicted\n\n#Y_predicted=regressor.predict(x_test)\n#Y_predicted","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:06:25.691947Z","iopub.execute_input":"2022-01-11T14:06:25.692510Z","iopub.status.idle":"2022-01-11T14:06:25.707606Z","shell.execute_reply.started":"2022-01-11T14:06:25.692474Z","shell.execute_reply":"2022-01-11T14:06:25.706595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Mean squared error: %.2f\" % mean_squared_error(y_test, Y_predicted))","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:06:45.602745Z","iopub.execute_input":"2022-01-11T14:06:45.603008Z","iopub.status.idle":"2022-01-11T14:06:45.608984Z","shell.execute_reply.started":"2022-01-11T14:06:45.602975Z","shell.execute_reply":"2022-01-11T14:06:45.608180Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Coefficient of determination: %.2f\" % r2_score(y_test, Y_predicted))","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:06:51.149815Z","iopub.execute_input":"2022-01-11T14:06:51.150080Z","iopub.status.idle":"2022-01-11T14:06:51.155922Z","shell.execute_reply.started":"2022-01-11T14:06:51.150044Z","shell.execute_reply":"2022-01-11T14:06:51.155020Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#print(cross_val_score(model, X, Y, cv=5, scoring=\"r2\").mean())","metadata":{"execution":{"iopub.status.busy":"2022-01-07T00:18:11.356532Z","iopub.execute_input":"2022-01-07T00:18:11.357581Z","iopub.status.idle":"2022-01-07T00:18:11.426276Z","shell.execute_reply.started":"2022-01-07T00:18:11.357527Z","shell.execute_reply":"2022-01-07T00:18:11.425167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:07:04.919876Z","iopub.execute_input":"2022-01-11T14:07:04.920170Z","iopub.status.idle":"2022-01-11T14:07:04.934243Z","shell.execute_reply.started":"2022-01-11T14:07:04.920138Z","shell.execute_reply":"2022-01-11T14:07:04.933520Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['date']=pd.to_datetime(test_df['date'])\ntest_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:07:13.560455Z","iopub.execute_input":"2022-01-11T14:07:13.561426Z","iopub.status.idle":"2022-01-11T14:07:13.579735Z","shell.execute_reply.started":"2022-01-11T14:07:13.561334Z","shell.execute_reply":"2022-01-11T14:07:13.578787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['year']=test_df['date'].dt.year\ntest_df['month']=test_df['date'].dt.month\ntest_df['day']=test_df['date'].dt.day\ntest_df","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:07:17.606080Z","iopub.execute_input":"2022-01-11T14:07:17.606892Z","iopub.status.idle":"2022-01-11T14:07:17.629767Z","shell.execute_reply.started":"2022-01-11T14:07:17.606837Z","shell.execute_reply":"2022-01-11T14:07:17.628722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:07:21.254860Z","iopub.execute_input":"2022-01-11T14:07:21.255682Z","iopub.status.idle":"2022-01-11T14:07:21.276357Z","shell.execute_reply.started":"2022-01-11T14:07:21.255629Z","shell.execute_reply":"2022-01-11T14:07:21.275410Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test_df['date']=test_df['date'].map(dt.datetime.toordinal)","metadata":{"execution":{"iopub.status.busy":"2022-01-06T16:31:03.280088Z","iopub.execute_input":"2022-01-06T16:31:03.280879Z","iopub.status.idle":"2022-01-06T16:31:03.284477Z","shell.execute_reply.started":"2022-01-06T16:31:03.280833Z","shell.execute_reply":"2022-01-06T16:31:03.283661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test_df","metadata":{"execution":{"iopub.status.busy":"2022-01-04T23:11:58.650905Z","iopub.execute_input":"2022-01-04T23:11:58.651472Z","iopub.status.idle":"2022-01-04T23:11:58.663708Z","shell.execute_reply.started":"2022-01-04T23:11:58.651433Z","shell.execute_reply":"2022-01-04T23:11:58.662758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test_df['country_enc']=lb_encoder.fit_transform(test_df['country'])\n#test_df['store_enc']=lb_encoder.fit_transform(test_df['store'])\n#test_df['product_enc']=lb_encoder.fit_transform(test_df['product'])","metadata":{"execution":{"iopub.status.busy":"2022-01-04T16:14:32.427647Z","iopub.execute_input":"2022-01-04T16:14:32.427977Z","iopub.status.idle":"2022-01-04T16:14:32.443928Z","shell.execute_reply.started":"2022-01-04T16:14:32.427944Z","shell.execute_reply":"2022-01-04T16:14:32.443183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df=pd.get_dummies(test_df, columns=['country'], prefix_sep= '_')\ntest_df=pd.get_dummies(test_df, columns=['store'], prefix_sep= '_')\ntest_df=pd.get_dummies(test_df, columns=['product'], prefix_sep= '_')\ntest_df","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:07:26.007258Z","iopub.execute_input":"2022-01-11T14:07:26.007535Z","iopub.status.idle":"2022-01-11T14:07:26.040336Z","shell.execute_reply.started":"2022-01-11T14:07:26.007504Z","shell.execute_reply":"2022-01-11T14:07:26.039364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:07:29.502361Z","iopub.execute_input":"2022-01-11T14:07:29.502918Z","iopub.status.idle":"2022-01-11T14:07:29.517733Z","shell.execute_reply.started":"2022-01-11T14:07:29.502875Z","shell.execute_reply":"2022-01-11T14:07:29.517210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test_df=test_df.drop(['country','store','product'], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T16:15:24.674913Z","iopub.execute_input":"2022-01-04T16:15:24.675357Z","iopub.status.idle":"2022-01-04T16:15:24.683226Z","shell.execute_reply.started":"2022-01-04T16:15:24.675308Z","shell.execute_reply":"2022-01-04T16:15:24.682247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df=test_df.drop(['date'], axis=1)\ntest_df","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:07:34.707987Z","iopub.execute_input":"2022-01-11T14:07:34.708599Z","iopub.status.idle":"2022-01-11T14:07:34.725496Z","shell.execute_reply.started":"2022-01-11T14:07:34.708551Z","shell.execute_reply":"2022-01-11T14:07:34.724890Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:10:25.911411Z","iopub.execute_input":"2022-01-11T14:10:25.911931Z","iopub.status.idle":"2022-01-11T14:10:25.922968Z","shell.execute_reply.started":"2022-01-11T14:10:25.911898Z","shell.execute_reply":"2022-01-11T14:10:25.922130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test_df= sm.add_constant(test_df)\n#X['const']\ntest_df['const']=X['const']\ntest_df","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:14:26.412735Z","iopub.execute_input":"2022-01-11T14:14:26.413767Z","iopub.status.idle":"2022-01-11T14:14:26.439849Z","shell.execute_reply.started":"2022-01-11T14:14:26.413723Z","shell.execute_reply":"2022-01-11T14:14:26.439038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# shift column 'Name' to first position\nfirst_column = test_df.pop('const')\n  \n# insert column using insert(position,column_name,\n# first_column) function\ntest_df.insert(0, 'const', first_column)","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:15:44.605501Z","iopub.execute_input":"2022-01-11T14:15:44.606112Z","iopub.status.idle":"2022-01-11T14:15:44.612332Z","shell.execute_reply.started":"2022-01-11T14:15:44.606059Z","shell.execute_reply":"2022-01-11T14:15:44.611722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:15:48.073326Z","iopub.execute_input":"2022-01-11T14:15:48.073715Z","iopub.status.idle":"2022-01-11T14:15:48.089756Z","shell.execute_reply.started":"2022-01-11T14:15:48.073686Z","shell.execute_reply":"2022-01-11T14:15:48.088915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#sc_test = StandardScaler()\n#test_df = sc_test.fit_transform(test_df)","metadata":{"execution":{"iopub.status.busy":"2022-01-06T16:36:48.959485Z","iopub.execute_input":"2022-01-06T16:36:48.959794Z","iopub.status.idle":"2022-01-06T16:36:48.969013Z","shell.execute_reply.started":"2022-01-06T16:36:48.959758Z","shell.execute_reply":"2022-01-06T16:36:48.968232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#poly_test_df = poly.fit_transform(test_df)","metadata":{"execution":{"iopub.status.busy":"2022-01-05T16:27:34.893789Z","iopub.execute_input":"2022-01-05T16:27:34.89481Z","iopub.status.idle":"2022-01-05T16:27:34.906972Z","shell.execute_reply.started":"2022-01-05T16:27:34.894756Z","shell.execute_reply":"2022-01-05T16:27:34.906156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#predicted_num_sold=regressor.predict(test_df)\n#predicted_num_sold","metadata":{"execution":{"iopub.status.busy":"2022-01-06T16:54:08.456456Z","iopub.execute_input":"2022-01-06T16:54:08.457376Z","iopub.status.idle":"2022-01-06T16:54:11.28008Z","shell.execute_reply.started":"2022-01-06T16:54:08.457334Z","shell.execute_reply":"2022-01-06T16:54:11.279453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#predicted_num_sold=model.predict(test_df)\n#predicted_num_sold\n\npredicted_num_sold=OLSmodel.predict(test_df)\npredicted_num_sold","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:15:53.906498Z","iopub.execute_input":"2022-01-11T14:15:53.906923Z","iopub.status.idle":"2022-01-11T14:15:53.919072Z","shell.execute_reply.started":"2022-01-11T14:15:53.906881Z","shell.execute_reply":"2022-01-11T14:15:53.918236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df=pd.read_csv('../input/tabular-playground-series-jan-2022/sample_submission.csv')\nsubmission_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:16:00.756958Z","iopub.execute_input":"2022-01-11T14:16:00.757233Z","iopub.status.idle":"2022-01-11T14:16:00.776675Z","shell.execute_reply.started":"2022-01-11T14:16:00.757206Z","shell.execute_reply":"2022-01-11T14:16:00.775809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df['num_sold']=predicted_num_sold","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:16:04.912786Z","iopub.execute_input":"2022-01-11T14:16:04.913027Z","iopub.status.idle":"2022-01-11T14:16:04.917886Z","shell.execute_reply.started":"2022-01-11T14:16:04.913002Z","shell.execute_reply":"2022-01-11T14:16:04.917059Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:16:06.810536Z","iopub.execute_input":"2022-01-11T14:16:06.810820Z","iopub.status.idle":"2022-01-11T14:16:06.822411Z","shell.execute_reply.started":"2022-01-11T14:16:06.810786Z","shell.execute_reply":"2022-01-11T14:16:06.821870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.to_csv('12th submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-01-11T14:16:32.403696Z","iopub.execute_input":"2022-01-11T14:16:32.404225Z","iopub.status.idle":"2022-01-11T14:16:32.436531Z","shell.execute_reply.started":"2022-01-11T14:16:32.404190Z","shell.execute_reply":"2022-01-11T14:16:32.435672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}