{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":84896,"databundleVersionId":10305135,"sourceType":"competition"},{"sourceId":9178166,"sourceType":"datasetVersion","datasetId":5547076}],"dockerImageVersionId":30804,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Random Guess within a certain range.\n\nAs part of an experimentation we will randomly choose our target within a range. The range is defined around the median in train data.\n\n#### This is by no mean a way to go in ML. But it is not forbidden to experiment.","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-27T00:03:31.197182Z","iopub.execute_input":"2024-12-27T00:03:31.197503Z","iopub.status.idle":"2024-12-27T00:03:32.277124Z","shell.execute_reply.started":"2024-12-27T00:03:31.19747Z","shell.execute_reply":"2024-12-27T00:03:32.27605Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"target = 'Premium Amount'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-27T00:03:32.279804Z","iopub.execute_input":"2024-12-27T00:03:32.280329Z","iopub.status.idle":"2024-12-27T00:03:32.285059Z","shell.execute_reply.started":"2024-12-27T00:03:32.280271Z","shell.execute_reply":"2024-12-27T00:03:32.28376Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/playground-series-s4e12/train.csv', index_col='id')\ntest = pd.read_csv('/kaggle/input/playground-series-s4e12/test.csv', index_col= 'id')\norig = pd.read_csv('/kaggle/input/insurance-premium-prediction/Insurance Premium Prediction Dataset.csv')\norig_c = orig[-orig[target].isna()]\ntrain_c = pd.concat([train, orig_c], ignore_index=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-27T00:03:32.28619Z","iopub.execute_input":"2024-12-27T00:03:32.286494Z","iopub.status.idle":"2024-12-27T00:03:44.325096Z","shell.execute_reply.started":"2024-12-27T00:03:32.286462Z","shell.execute_reply":"2024-12-27T00:03:44.324216Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sub = pd.read_csv('/kaggle/input/playground-series-s4e12/sample_submission.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-27T00:03:44.326186Z","iopub.execute_input":"2024-12-27T00:03:44.326497Z","iopub.status.idle":"2024-12-27T00:03:44.606869Z","shell.execute_reply.started":"2024-12-27T00:03:44.326466Z","shell.execute_reply":"2024-12-27T00:03:44.605771Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"#### Get the median target from combined train and original sets.","metadata":{}},{"cell_type":"code","source":"use_orig = False\n\nif use_orig:\n    y = train_c.pop(target)\nelse:\n    y = train.pop(target)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-27T00:03:44.608384Z","iopub.execute_input":"2024-12-27T00:03:44.608815Z","iopub.status.idle":"2024-12-27T00:03:44.614268Z","shell.execute_reply.started":"2024-12-27T00:03:44.608766Z","shell.execute_reply":"2024-12-27T00:03:44.613256Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"#### Get the median and std","metadata":{}},{"cell_type":"code","source":"median = y.median()\nstd = y.std()\nmedian, std","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-27T00:03:44.615759Z","iopub.execute_input":"2024-12-27T00:03:44.61646Z","iopub.status.idle":"2024-12-27T00:03:44.672232Z","shell.execute_reply.started":"2024-12-27T00:03:44.616412Z","shell.execute_reply":"2024-12-27T00:03:44.671221Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"#### Let try a lucky guess within the certain margin","metadata":{}},{"cell_type":"code","source":"import random\ndiv=\nguess = pd.Series([random.randrange(int(median-std/div), int(median+2*std/div)) for rand in range(sub.shape[0])])\n# guess = pd.Series([random.randrange(600, 900) for rand in range (sub.shape[0])])\nguess[:10]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-27T00:03:44.674907Z","iopub.execute_input":"2024-12-27T00:03:44.675227Z","iopub.status.idle":"2024-12-27T00:03:45.953871Z","shell.execute_reply.started":"2024-12-27T00:03:44.675195Z","shell.execute_reply":"2024-12-27T00:03:45.952836Z"},"_kg_hide-input":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"#### How does it look like?","metadata":{}},{"cell_type":"code","source":"pd.Series(guess).plot.kde()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-27T00:03:45.954946Z","iopub.execute_input":"2024-12-27T00:03:45.955213Z","iopub.status.idle":"2024-12-27T00:04:01.812213Z","shell.execute_reply.started":"2024-12-27T00:03:45.955185Z","shell.execute_reply":"2024-12-27T00:04:01.810933Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"#### Here we go!","metadata":{}},{"cell_type":"code","source":"sub[target] = guess\nsub.head(5)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-27T00:04:01.813849Z","iopub.execute_input":"2024-12-27T00:04:01.814382Z","iopub.status.idle":"2024-12-27T00:04:01.829651Z","shell.execute_reply.started":"2024-12-27T00:04:01.814318Z","shell.execute_reply":"2024-12-27T00:04:01.828415Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"#### How lucky are we? Let's submit and find out.","metadata":{}},{"cell_type":"code","source":"sub.to_csv('submission.csv', index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-27T00:04:01.831084Z","iopub.execute_input":"2024-12-27T00:04:01.831535Z","iopub.status.idle":"2024-12-27T00:04:02.620673Z","shell.execute_reply.started":"2024-12-27T00:04:01.831484Z","shell.execute_reply":"2024-12-27T00:04:02.619372Z"}},"outputs":[],"execution_count":null}]}