{"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-12T12:22:08.645539Z","iopub.execute_input":"2022-07-12T12:22:08.646619Z","iopub.status.idle":"2022-07-12T12:22:08.678463Z","shell.execute_reply.started":"2022-07-12T12:22:08.646481Z","shell.execute_reply":"2022-07-12T12:22:08.677195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from kmodes.kprototypes import KPrototypes","metadata":{"execution":{"iopub.status.busy":"2022-07-12T12:22:08.684682Z","iopub.execute_input":"2022-07-12T12:22:08.685392Z","iopub.status.idle":"2022-07-12T12:22:09.793638Z","shell.execute_reply.started":"2022-07-12T12:22:08.685349Z","shell.execute_reply":"2022-07-12T12:22:09.792517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv(\"/kaggle/input/tabular-playground-series-jul-2022/data.csv\", index_col='id')\ndata.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T12:22:09.795867Z","iopub.execute_input":"2022-07-12T12:22:09.796344Z","iopub.status.idle":"2022-07-12T12:22:11.109813Z","shell.execute_reply.started":"2022-07-12T12:22:09.796296Z","shell.execute_reply":"2022-07-12T12:22:11.108499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_col = ['f_07','f_08','f_09','f_10','f_11','f_12','f_13']\nnum_col = ['f_22', 'f_23', 'f_24', 'f_25', 'f_26', 'f_27', 'f_28']\ndata_cat = data[cat_col]\ndata_num = data[num_col]","metadata":{"execution":{"iopub.status.busy":"2022-07-12T12:27:00.027941Z","iopub.execute_input":"2022-07-12T12:27:00.028383Z","iopub.status.idle":"2022-07-12T12:27:00.037603Z","shell.execute_reply.started":"2022-07-12T12:27:00.028346Z","shell.execute_reply":"2022-07-12T12:27:00.036488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn import preprocessing\n\nx = data_num.values\nmin_max_scaler = preprocessing.MinMaxScaler()\nx_scaled = min_max_scaler.fit_transform(x)\n\nrb_scalar = preprocessing.PowerTransformer()\nx_scaled = rb_scalar.fit_transform(x_scaled)\ndata_num_scaled = pd.DataFrame(x_scaled, columns=data_num.columns)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T12:27:00.076677Z","iopub.execute_input":"2022-07-12T12:27:00.077359Z","iopub.status.idle":"2022-07-12T12:27:00.806562Z","shell.execute_reply.started":"2022-07-12T12:27:00.077313Z","shell.execute_reply":"2022-07-12T12:27:00.805602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.concat([data_cat, data_num_scaled], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T12:27:00.809736Z","iopub.execute_input":"2022-07-12T12:27:00.810552Z","iopub.status.idle":"2022-07-12T12:27:00.820494Z","shell.execute_reply.started":"2022-07-12T12:27:00.810511Z","shell.execute_reply":"2022-07-12T12:27:00.819081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.iloc[:,list(range(0, 7))].head()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T12:27:00.821855Z","iopub.execute_input":"2022-07-12T12:27:00.822214Z","iopub.status.idle":"2022-07-12T12:27:00.843698Z","shell.execute_reply.started":"2022-07-12T12:27:00.822181Z","shell.execute_reply":"2022-07-12T12:27:00.842452Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" data_predicted = KPrototypes(n_clusters=7, init='Huang', n_init=1, verbose=2).fit_predict(data, categorical=list(range(0, 7)))","metadata":{"execution":{"iopub.status.busy":"2022-07-12T12:27:00.846645Z","iopub.execute_input":"2022-07-12T12:27:00.847789Z","iopub.status.idle":"2022-07-12T12:42:55.461836Z","shell.execute_reply.started":"2022-07-12T12:27:00.847737Z","shell.execute_reply":"2022-07-12T12:42:55.460833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_predicted[0:10]","metadata":{"execution":{"iopub.status.busy":"2022-07-12T12:42:55.464017Z","iopub.execute_input":"2022-07-12T12:42:55.464894Z","iopub.status.idle":"2022-07-12T12:42:55.474558Z","shell.execute_reply.started":"2022-07-12T12:42:55.464838Z","shell.execute_reply":"2022-07-12T12:42:55.473423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit_df = pd.read_csv(\"/kaggle/input/tabular-playground-series-jul-2022/sample_submission.csv\")\nsubmit_df['Predicted'] = data_predicted","metadata":{"execution":{"iopub.status.busy":"2022-07-12T12:42:55.475802Z","iopub.execute_input":"2022-07-12T12:42:55.476190Z","iopub.status.idle":"2022-07-12T12:42:55.517435Z","shell.execute_reply.started":"2022-07-12T12:42:55.476156Z","shell.execute_reply":"2022-07-12T12:42:55.516147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit_df['Predicted'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T12:42:55.519151Z","iopub.execute_input":"2022-07-12T12:42:55.520007Z","iopub.status.idle":"2022-07-12T12:42:55.532071Z","shell.execute_reply.started":"2022-07-12T12:42:55.519953Z","shell.execute_reply":"2022-07-12T12:42:55.531186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit_df.to_csv(\"sample_submission_kprototype_ImpCol_Num-Scaled.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T12:42:55.533318Z","iopub.execute_input":"2022-07-12T12:42:55.533806Z","iopub.status.idle":"2022-07-12T12:42:55.639672Z","shell.execute_reply.started":"2022-07-12T12:42:55.533773Z","shell.execute_reply":"2022-07-12T12:42:55.638445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### **Bad score**\n\nScore: 0.04026\n\nIt is not working. Let me know if there are any mistakes in this notebook or tips to improve here.","metadata":{}}]}