{"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 itertools","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-01T14:26:06.049197Z","iopub.execute_input":"2022-08-01T14:26:06.049630Z","iopub.status.idle":"2022-08-01T14:26:06.079506Z","shell.execute_reply.started":"2022-08-01T14:26:06.049530Z","shell.execute_reply":"2022-08-01T14:26:06.078310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('../input/tabular-playground-series-aug-2022/train.csv')\ntest = pd.read_csv('../input/tabular-playground-series-aug-2022/test.csv')\nsubmission = pd.read_csv('../input/tabular-playground-series-aug-2022/sample_submission.csv')\nprint(f'train {train.shape}, test {test.shape}')","metadata":{"execution":{"iopub.status.busy":"2022-08-01T14:26:06.082165Z","iopub.execute_input":"2022-08-01T14:26:06.082893Z","iopub.status.idle":"2022-08-01T14:26:06.364818Z","shell.execute_reply.started":"2022-08-01T14:26:06.082845Z","shell.execute_reply":"2022-08-01T14:26:06.364065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### It seems that there are 4 category features in data as \"attribute_0\",\"attribute_1\",\"attribute_2\",\"attribute_3\"\n#### Trying to find the interaction between them, I create some new features like below.","metadata":{}},{"cell_type":"code","source":"# combine attribute_0 and attribute_1\ntrain['attribute_01'] = train['attribute_0'] + ' ' + train['attribute_1']\ntest['attribute_01'] = test['attribute_0'] + ' ' + test['attribute_1']\n# combine attribute_2 and attribute_3\ntrain['attribute_23'] = train['attribute_2'].astype(int).astype(str) + ' ' + train['attribute_3'].astype(int).astype(str)\ntest['attribute_23'] = test['attribute_2'].astype(int).astype(str) + ' ' + test['attribute_3'].astype(int).astype(str)\n# combine all of them\ntrain['attribute_0123'] = train['attribute_0'] + ' ' + train['attribute_1'] + ' ' + train['attribute_2'].astype(int).astype(str) + ' ' + train['attribute_3'].astype(int).astype(str)\ntest['attribute_0123'] = test['attribute_0'] + ' ' + test['attribute_1'] + ' ' + test['attribute_2'].astype(int).astype(str) + ' ' + test['attribute_3'].astype(int).astype(str)","metadata":{"execution":{"iopub.status.busy":"2022-08-01T14:26:06.366139Z","iopub.execute_input":"2022-08-01T14:26:06.366401Z","iopub.status.idle":"2022-08-01T14:26:06.615505Z","shell.execute_reply.started":"2022-08-01T14:26:06.366375Z","shell.execute_reply":"2022-08-01T14:26:06.614083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['attribute_01'].value_counts().sort_index()","metadata":{"execution":{"iopub.status.busy":"2022-08-01T14:26:06.618469Z","iopub.execute_input":"2022-08-01T14:26:06.619065Z","iopub.status.idle":"2022-08-01T14:26:06.644093Z","shell.execute_reply.started":"2022-08-01T14:26:06.619027Z","shell.execute_reply":"2022-08-01T14:26:06.643028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" for i in itertools.product(list(train['attribute_0'].unique()), list(train['attribute_1'].unique())):\n        print(i)","metadata":{"execution":{"iopub.status.busy":"2022-08-01T14:26:06.646209Z","iopub.execute_input":"2022-08-01T14:26:06.646540Z","iopub.status.idle":"2022-08-01T14:26:06.658074Z","shell.execute_reply.started":"2022-08-01T14:26:06.646508Z","shell.execute_reply":"2022-08-01T14:26:06.657488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**attribute_0** and **attribute_1** in train should be 6 combinations, but there are actually 4 combinations.","metadata":{}},{"cell_type":"code","source":"test['attribute_01'].value_counts().sort_index()","metadata":{"execution":{"iopub.status.busy":"2022-08-01T14:26:06.659149Z","iopub.execute_input":"2022-08-01T14:26:06.659525Z","iopub.status.idle":"2022-08-01T14:26:06.671340Z","shell.execute_reply.started":"2022-08-01T14:26:06.659502Z","shell.execute_reply":"2022-08-01T14:26:06.670240Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in itertools.product(list(test['attribute_0'].unique()), list(test['attribute_1'].unique())):\n    print(i)","metadata":{"execution":{"iopub.status.busy":"2022-08-01T14:26:06.673039Z","iopub.execute_input":"2022-08-01T14:26:06.673361Z","iopub.status.idle":"2022-08-01T14:26:06.684739Z","shell.execute_reply.started":"2022-08-01T14:26:06.673332Z","shell.execute_reply":"2022-08-01T14:26:06.683764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**attribute_0** and **attribute_1** in test should be 6 combinations, but there are actually 3 combinations.","metadata":{"execution":{"iopub.status.busy":"2022-08-01T07:55:50.219781Z","iopub.execute_input":"2022-08-01T07:55:50.220228Z","iopub.status.idle":"2022-08-01T07:55:50.228701Z","shell.execute_reply.started":"2022-08-01T07:55:50.220195Z","shell.execute_reply":"2022-08-01T07:55:50.227013Z"}}},{"cell_type":"code","source":"train['attribute_23'].value_counts().sort_index()","metadata":{"execution":{"iopub.status.busy":"2022-08-01T14:26:06.685885Z","iopub.execute_input":"2022-08-01T14:26:06.686162Z","iopub.status.idle":"2022-08-01T14:26:06.700442Z","shell.execute_reply.started":"2022-08-01T14:26:06.686132Z","shell.execute_reply":"2022-08-01T14:26:06.699727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in itertools.product(list(train['attribute_2'].unique()), list(train['attribute_3'].unique())):\n    print(i)","metadata":{"execution":{"iopub.status.busy":"2022-08-01T14:26:06.701618Z","iopub.execute_input":"2022-08-01T14:26:06.702318Z","iopub.status.idle":"2022-08-01T14:26:06.708683Z","shell.execute_reply.started":"2022-08-01T14:26:06.702290Z","shell.execute_reply":"2022-08-01T14:26:06.707688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**attribute_2** and **attribute_3** in train should be 16 combinations, but there are actually 5 combinations.","metadata":{"execution":{"iopub.status.busy":"2022-08-01T07:58:48.716198Z","iopub.execute_input":"2022-08-01T07:58:48.717179Z","iopub.status.idle":"2022-08-01T07:58:48.727427Z","shell.execute_reply.started":"2022-08-01T07:58:48.717143Z","shell.execute_reply":"2022-08-01T07:58:48.725436Z"}}},{"cell_type":"code","source":"test['attribute_23'].value_counts().sort_index()","metadata":{"execution":{"iopub.status.busy":"2022-08-01T14:26:06.712222Z","iopub.execute_input":"2022-08-01T14:26:06.712823Z","iopub.status.idle":"2022-08-01T14:26:06.726116Z","shell.execute_reply.started":"2022-08-01T14:26:06.712784Z","shell.execute_reply":"2022-08-01T14:26:06.725381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in itertools.product(list(test['attribute_2'].unique()), list(test['attribute_3'].unique())):\n    print(i)","metadata":{"execution":{"iopub.status.busy":"2022-08-01T14:26:06.727153Z","iopub.execute_input":"2022-08-01T14:26:06.727614Z","iopub.status.idle":"2022-08-01T14:26:06.739913Z","shell.execute_reply.started":"2022-08-01T14:26:06.727554Z","shell.execute_reply":"2022-08-01T14:26:06.738632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**attribute_2** and **attribute_3** in test should be 12 combinations, but there are actually 4 combinations.","metadata":{}},{"cell_type":"markdown","source":"#### The more interseting after combining all of them:","metadata":{}},{"cell_type":"code","source":"train['attribute_0123'].value_counts().sort_index()","metadata":{"execution":{"iopub.status.busy":"2022-08-01T14:26:06.742534Z","iopub.execute_input":"2022-08-01T14:26:06.743484Z","iopub.status.idle":"2022-08-01T14:26:06.755071Z","shell.execute_reply.started":"2022-08-01T14:26:06.743457Z","shell.execute_reply":"2022-08-01T14:26:06.754007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"n = 0\nfor i in itertools.product(list(train['attribute_0'].unique()), list(train['attribute_1'].unique()), list(train['attribute_2'].unique()), list(train['attribute_3'].unique())):\n    print(i)\n    n += 1\nprint(n)","metadata":{"execution":{"iopub.status.busy":"2022-08-01T14:26:06.756239Z","iopub.execute_input":"2022-08-01T14:26:06.756910Z","iopub.status.idle":"2022-08-01T14:26:06.772925Z","shell.execute_reply.started":"2022-08-01T14:26:06.756881Z","shell.execute_reply":"2022-08-01T14:26:06.771505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**attribute_0**, **attribute_1**, **attribute_2** and **attribute_3** in train should be 96 combinations, but there are actually 5 combinations.","metadata":{"execution":{"iopub.status.busy":"2022-08-01T08:05:45.261971Z","iopub.execute_input":"2022-08-01T08:05:45.262430Z","iopub.status.idle":"2022-08-01T08:05:45.271248Z","shell.execute_reply.started":"2022-08-01T08:05:45.262396Z","shell.execute_reply":"2022-08-01T08:05:45.269315Z"}}},{"cell_type":"code","source":"test['attribute_0123'].value_counts().sort_index()","metadata":{"execution":{"iopub.status.busy":"2022-08-01T14:26:06.774401Z","iopub.execute_input":"2022-08-01T14:26:06.775363Z","iopub.status.idle":"2022-08-01T14:26:06.789164Z","shell.execute_reply.started":"2022-08-01T14:26:06.775332Z","shell.execute_reply":"2022-08-01T14:26:06.788371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"n = 0\nfor i in itertools.product(list(test['attribute_0'].unique()), list(test['attribute_1'].unique()), list(test['attribute_2'].unique()), list(test['attribute_3'].unique())):\n    print(i)\n    n += 1\nprint(n)","metadata":{"execution":{"iopub.status.busy":"2022-08-01T14:26:06.790239Z","iopub.execute_input":"2022-08-01T14:26:06.790963Z","iopub.status.idle":"2022-08-01T14:26:06.804447Z","shell.execute_reply.started":"2022-08-01T14:26:06.790932Z","shell.execute_reply":"2022-08-01T14:26:06.803029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**attribute_0**, **attribute_1**, **attribute_2** and **attribute_3** in test should be 72 combinations, but there are actually 4 combinations.","metadata":{}},{"cell_type":"markdown","source":"#### I doubt whether this is meaningful. Do you have any ideas?","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}