{"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","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-13T22:55:25.986257Z","iopub.execute_input":"2022-07-13T22:55:25.986898Z","iopub.status.idle":"2022-07-13T22:55:26.015998Z","shell.execute_reply.started":"2022-07-13T22:55:25.986773Z","shell.execute_reply":"2022-07-13T22:55:26.014952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv('/kaggle/input/tabular-playground-series-jul-2022/data.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-13T22:55:28.189139Z","iopub.execute_input":"2022-07-13T22:55:28.191773Z","iopub.status.idle":"2022-07-13T22:55:29.437260Z","shell.execute_reply.started":"2022-07-13T22:55:28.191736Z","shell.execute_reply":"2022-07-13T22:55:29.435951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-13T22:55:29.442851Z","iopub.execute_input":"2022-07-13T22:55:29.443297Z","iopub.status.idle":"2022-07-13T22:55:29.845610Z","shell.execute_reply.started":"2022-07-13T22:55:29.443256Z","shell.execute_reply":"2022-07-13T22:55:29.844462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-13T23:21:43.604194Z","iopub.execute_input":"2022-07-13T23:21:43.604669Z","iopub.status.idle":"2022-07-13T23:21:43.635705Z","shell.execute_reply.started":"2022-07-13T23:21:43.604624Z","shell.execute_reply":"2022-07-13T23:21:43.634488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from matplotlib import pyplot as plt\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-07-13T22:55:29.850259Z","iopub.execute_input":"2022-07-13T22:55:29.850938Z","iopub.status.idle":"2022-07-13T22:55:31.173435Z","shell.execute_reply.started":"2022-07-13T22:55:29.850877Z","shell.execute_reply":"2022-07-13T22:55:31.165800Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(40, 25))\nsns.set_style('white')\nmask = np.triu(np.ones_like(data.corr(), dtype=np.bool))\nheatmap = sns.heatmap(data.corr(), mask=mask,annot=True, cmap='BrBG', linewidths = 2)\nheatmap.set_title('Triangle Correlation Heatmap', fontdict={'fontsize':30}, pad=16);","metadata":{"execution":{"iopub.status.busy":"2022-07-13T22:55:31.175037Z","iopub.execute_input":"2022-07-13T22:55:31.175443Z","iopub.status.idle":"2022-07-13T22:55:34.678599Z","shell.execute_reply.started":"2022-07-13T22:55:31.175405Z","shell.execute_reply":"2022-07-13T22:55:34.676970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"f7, 8 9 10 11 12 22 23 24 25","metadata":{}},{"cell_type":"code","source":"data = data.drop(['id'], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T22:55:34.679722Z","iopub.execute_input":"2022-07-13T22:55:34.680405Z","iopub.status.idle":"2022-07-13T22:55:34.692301Z","shell.execute_reply.started":"2022-07-13T22:55:34.680355Z","shell.execute_reply":"2022-07-13T22:55:34.691145Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"best_features =[ 'f_07','f_08', 'f_09', 'f_10', 'f_11', 'f_12', 'f_13', 'f_22','f_23', 'f_24', 'f_25','f_26', 'f_27', 'f_28']","metadata":{"execution":{"iopub.status.busy":"2022-07-13T22:55:34.694105Z","iopub.execute_input":"2022-07-13T22:55:34.694565Z","iopub.status.idle":"2022-07-13T22:55:34.701821Z","shell.execute_reply.started":"2022-07-13T22:55:34.694524Z","shell.execute_reply":"2022-07-13T22:55:34.700275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Normalize data\n","metadata":{}},{"cell_type":"code","source":"from sklearn.preprocessing import PowerTransformer","metadata":{"execution":{"iopub.status.busy":"2022-07-13T22:55:34.706700Z","iopub.execute_input":"2022-07-13T22:55:34.707765Z","iopub.status.idle":"2022-07-13T22:55:34.769887Z","shell.execute_reply.started":"2022-07-13T22:55:34.707727Z","shell.execute_reply":"2022-07-13T22:55:34.768793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pt = PowerTransformer()\ndata_ = pt.fit_transform(data[best_features])\ndata_ = pd.DataFrame(data_, columns = best_features)\ndata_.head(3)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T22:55:34.771472Z","iopub.execute_input":"2022-07-13T22:55:34.771947Z","iopub.status.idle":"2022-07-13T22:55:36.459753Z","shell.execute_reply.started":"2022-07-13T22:55:34.771891Z","shell.execute_reply":"2022-07-13T22:55:36.458388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = data_","metadata":{"execution":{"iopub.status.busy":"2022-07-13T22:55:36.461708Z","iopub.execute_input":"2022-07-13T22:55:36.462123Z","iopub.status.idle":"2022-07-13T22:55:36.467019Z","shell.execute_reply.started":"2022-07-13T22:55:36.462082Z","shell.execute_reply":"2022-07-13T22:55:36.465771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-13T22:55:36.469048Z","iopub.execute_input":"2022-07-13T22:55:36.469836Z","iopub.status.idle":"2022-07-13T22:55:36.480378Z","shell.execute_reply.started":"2022-07-13T22:55:36.469778Z","shell.execute_reply":"2022-07-13T22:55:36.479384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.mixture import BayesianGaussianMixture","metadata":{"execution":{"iopub.status.busy":"2022-07-13T22:55:36.483311Z","iopub.execute_input":"2022-07-13T22:55:36.484282Z","iopub.status.idle":"2022-07-13T22:55:36.722333Z","shell.execute_reply.started":"2022-07-13T22:55:36.484241Z","shell.execute_reply":"2022-07-13T22:55:36.721392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"n_clusters = 7\nkmeans = BayesianGaussianMixture(n_components = n_clusters, max_iter=50, random_state=42, n_init = 10).fit(data_.head(40000))\n\n","metadata":{"execution":{"iopub.status.busy":"2022-07-13T23:28:15.328008Z","iopub.execute_input":"2022-07-13T23:28:15.329115Z","iopub.status.idle":"2022-07-13T23:28:37.685014Z","shell.execute_reply.started":"2022-07-13T23:28:15.329062Z","shell.execute_reply":"2022-07-13T23:28:37.683962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = kmeans.predict(data_)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T23:28:37.688304Z","iopub.execute_input":"2022-07-13T23:28:37.689834Z","iopub.status.idle":"2022-07-13T23:28:37.868974Z","shell.execute_reply.started":"2022-07-13T23:28:37.689796Z","shell.execute_reply":"2022-07-13T23:28:37.867776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv(\"../input/tabular-playground-series-jul-2022/sample_submission.csv\")\n","metadata":{"execution":{"iopub.status.busy":"2022-07-13T23:28:37.874738Z","iopub.execute_input":"2022-07-13T23:28:37.877430Z","iopub.status.idle":"2022-07-13T23:28:37.919108Z","shell.execute_reply.started":"2022-07-13T23:28:37.877382Z","shell.execute_reply":"2022-07-13T23:28:37.917948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission[\"Predicted\"] = predictions\nsubmission.to_csv(\"submission.csv\", index = False)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T23:28:37.925255Z","iopub.execute_input":"2022-07-13T23:28:37.927982Z","iopub.status.idle":"2022-07-13T23:28:38.096282Z","shell.execute_reply.started":"2022-07-13T23:28:37.927933Z","shell.execute_reply":"2022-07-13T23:28:38.094473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}