{"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":"markdown","source":"# Importing the libraries","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nfrom sklearn.preprocessing import MinMaxScaler\nfrom sklearn.decomposition import PCA\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.cluster import DBSCAN\nfrom sklearn.mixture import GaussianMixture,BayesianGaussianMixture\nfrom sklearn.preprocessing import PowerTransformer","metadata":{"execution":{"iopub.status.busy":"2022-07-22T08:10:14.965304Z","iopub.execute_input":"2022-07-22T08:10:14.965679Z","iopub.status.idle":"2022-07-22T08:10:14.971675Z","shell.execute_reply.started":"2022-07-22T08:10:14.965649Z","shell.execute_reply":"2022-07-22T08:10:14.970457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Importing data","metadata":{}},{"cell_type":"code","source":"data = pd.read_csv('../input/tabular-playground-series-jul-2022/data.csv')\nsub_df = pd.read_csv('../input/tabular-playground-series-jul-2022/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-22T07:49:04.662616Z","iopub.execute_input":"2022-07-22T07:49:04.662943Z","iopub.status.idle":"2022-07-22T07:49:05.705620Z","shell.execute_reply.started":"2022-07-22T07:49:04.662909Z","shell.execute_reply":"2022-07-22T07:49:05.704679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data","metadata":{"execution":{"iopub.status.busy":"2022-07-22T07:49:05.707059Z","iopub.execute_input":"2022-07-22T07:49:05.707401Z","iopub.status.idle":"2022-07-22T07:49:05.762652Z","shell.execute_reply.started":"2022-07-22T07:49:05.707366Z","shell.execute_reply":"2022-07-22T07:49:05.761566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.isnull().sum().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-22T07:49:05.764240Z","iopub.execute_input":"2022-07-22T07:49:05.764647Z","iopub.status.idle":"2022-07-22T07:49:05.779192Z","shell.execute_reply.started":"2022-07-22T07:49:05.764610Z","shell.execute_reply":"2022-07-22T07:49:05.778378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df","metadata":{"execution":{"iopub.status.busy":"2022-07-22T07:49:05.782602Z","iopub.execute_input":"2022-07-22T07:49:05.782919Z","iopub.status.idle":"2022-07-22T07:49:05.794512Z","shell.execute_reply.started":"2022-07-22T07:49:05.782891Z","shell.execute_reply":"2022-07-22T07:49:05.793150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Checking correlation between data","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(30,30))\nsns.heatmap(data.corr(),annot=True,cmap='viridis')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-22T07:49:05.796155Z","iopub.execute_input":"2022-07-22T07:49:05.796649Z","iopub.status.idle":"2022-07-22T07:49:09.645151Z","shell.execute_reply.started":"2022-07-22T07:49:05.796608Z","shell.execute_reply":"2022-07-22T07:49:09.644234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=data.drop(columns='id',axis=1)\ndata","metadata":{"execution":{"iopub.status.busy":"2022-07-22T07:49:09.646163Z","iopub.execute_input":"2022-07-22T07:49:09.646513Z","iopub.status.idle":"2022-07-22T07:49:09.701423Z","shell.execute_reply.started":"2022-07-22T07:49:09.646464Z","shell.execute_reply":"2022-07-22T07:49:09.700472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Applying min max scaler to the data","metadata":{}},{"cell_type":"code","source":"scaler=MinMaxScaler(feature_range=(0,1))\nscaled_data=scaler.fit_transform(data)\nscaled_data","metadata":{"execution":{"iopub.status.busy":"2022-07-22T07:49:09.702900Z","iopub.execute_input":"2022-07-22T07:49:09.703491Z","iopub.status.idle":"2022-07-22T07:49:09.746094Z","shell.execute_reply.started":"2022-07-22T07:49:09.703454Z","shell.execute_reply":"2022-07-22T07:49:09.745068Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaled_data=pd.DataFrame(scaled_data,columns=data.columns)\nscaled_data","metadata":{"execution":{"iopub.status.busy":"2022-07-22T07:49:09.748777Z","iopub.execute_input":"2022-07-22T07:49:09.749123Z","iopub.status.idle":"2022-07-22T07:49:09.786172Z","shell.execute_reply.started":"2022-07-22T07:49:09.749095Z","shell.execute_reply":"2022-07-22T07:49:09.785021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Applying power transformer to the scaled data\nPower transformer helps the data to be more Gaussian in nature.","metadata":{}},{"cell_type":"code","source":"transformer = PowerTransformer()\nX=transformer.fit_transform(scaled_data)\nX=pd.DataFrame(X,columns=data.columns)\nX","metadata":{"execution":{"iopub.status.busy":"2022-07-22T08:37:12.050087Z","iopub.execute_input":"2022-07-22T08:37:12.050432Z","iopub.status.idle":"2022-07-22T08:37:15.034572Z","shell.execute_reply.started":"2022-07-22T08:37:12.050404Z","shell.execute_reply":"2022-07-22T08:37:15.033549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Now applying Gaussian Mixture(The ultimate clustering algorithm)","metadata":{}},{"cell_type":"code","source":"gm=GaussianMixture(n_components=7,random_state=1)\ngm_labels=gm.fit_predict(X)","metadata":{"execution":{"iopub.status.busy":"2022-07-22T08:30:53.180316Z","iopub.execute_input":"2022-07-22T08:30:53.180697Z","iopub.status.idle":"2022-07-22T08:31:08.011163Z","shell.execute_reply.started":"2022-07-22T08:30:53.180667Z","shell.execute_reply":"2022-07-22T08:31:08.009964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gm_labels","metadata":{"execution":{"iopub.status.busy":"2022-07-22T08:31:09.739527Z","iopub.execute_input":"2022-07-22T08:31:09.740198Z","iopub.status.idle":"2022-07-22T08:31:09.747760Z","shell.execute_reply.started":"2022-07-22T08:31:09.740159Z","shell.execute_reply":"2022-07-22T08:31:09.746399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Building the submission dataframe","metadata":{}},{"cell_type":"code","source":"sub=pd.DataFrame({'Id':sub_df['Id'],'Predicted':gm_labels})","metadata":{"execution":{"iopub.status.busy":"2022-07-22T08:31:18.324547Z","iopub.execute_input":"2022-07-22T08:31:18.325761Z","iopub.status.idle":"2022-07-22T08:31:18.332171Z","shell.execute_reply.started":"2022-07-22T08:31:18.325716Z","shell.execute_reply":"2022-07-22T08:31:18.330948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub","metadata":{"execution":{"iopub.status.busy":"2022-07-22T08:31:19.724665Z","iopub.execute_input":"2022-07-22T08:31:19.725034Z","iopub.status.idle":"2022-07-22T08:31:19.740079Z","shell.execute_reply.started":"2022-07-22T08:31:19.725003Z","shell.execute_reply":"2022-07-22T08:31:19.738917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub['Predicted'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-22T08:31:36.940310Z","iopub.execute_input":"2022-07-22T08:31:36.940675Z","iopub.status.idle":"2022-07-22T08:31:36.952058Z","shell.execute_reply.started":"2022-07-22T08:31:36.940645Z","shell.execute_reply":"2022-07-22T08:31:36.950879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Making the submission CSV file","metadata":{}},{"cell_type":"code","source":"sub.to_csv('submission5.csv',index=None)","metadata":{"execution":{"iopub.status.busy":"2022-07-22T08:31:45.550172Z","iopub.execute_input":"2022-07-22T08:31:45.550586Z","iopub.status.idle":"2022-07-22T08:31:45.695557Z","shell.execute_reply.started":"2022-07-22T08:31:45.550552Z","shell.execute_reply":"2022-07-22T08:31:45.694541Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Thanks for reading this notebook. If you like then upvote it.","metadata":{}}]}