{"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-06T03:52:56.849831Z","iopub.execute_input":"2022-07-06T03:52:56.850273Z","iopub.status.idle":"2022-07-06T03:52:56.888315Z","shell.execute_reply.started":"2022-07-06T03:52:56.850187Z","shell.execute_reply":"2022-07-06T03:52:56.887448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=pd.read_csv('/kaggle/input/tabular-playground-series-jul-2022/data.csv')\nsubmission=pd.read_csv('/kaggle/input/tabular-playground-series-jul-2022/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:27:47.541454Z","iopub.execute_input":"2022-07-06T04:27:47.541865Z","iopub.status.idle":"2022-07-06T04:27:48.397325Z","shell.execute_reply.started":"2022-07-06T04:27:47.541829Z","shell.execute_reply":"2022-07-06T04:27:48.396389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-06T03:54:31.052080Z","iopub.execute_input":"2022-07-06T03:54:31.052620Z","iopub.status.idle":"2022-07-06T03:54:31.065074Z","shell.execute_reply.started":"2022-07-06T03:54:31.052573Z","shell.execute_reply":"2022-07-06T03:54:31.063683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-06T03:54:39.708297Z","iopub.execute_input":"2022-07-06T03:54:39.708696Z","iopub.status.idle":"2022-07-06T03:54:39.717503Z","shell.execute_reply.started":"2022-07-06T03:54:39.708665Z","shell.execute_reply":"2022-07-06T03:54:39.715830Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.max_columns', None)","metadata":{"execution":{"iopub.status.busy":"2022-07-06T03:57:19.166947Z","iopub.execute_input":"2022-07-06T03:57:19.167341Z","iopub.status.idle":"2022-07-06T03:57:19.173577Z","shell.execute_reply.started":"2022-07-06T03:57:19.167312Z","shell.execute_reply":"2022-07-06T03:57:19.172163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ndata.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-06T03:57:19.402104Z","iopub.execute_input":"2022-07-06T03:57:19.403323Z","iopub.status.idle":"2022-07-06T03:57:19.433154Z","shell.execute_reply.started":"2022-07-06T03:57:19.403253Z","shell.execute_reply":"2022-07-06T03:57:19.431965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"columns=data.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-06T03:57:47.751225Z","iopub.execute_input":"2022-07-06T03:57:47.751802Z","iopub.status.idle":"2022-07-06T03:57:47.757998Z","shell.execute_reply.started":"2022-07-06T03:57:47.751732Z","shell.execute_reply":"2022-07-06T03:57:47.756804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(1,len(columns)):\n    print(data[columns[i]].isnull().sum())","metadata":{"execution":{"iopub.status.busy":"2022-07-06T03:58:51.071528Z","iopub.execute_input":"2022-07-06T03:58:51.071921Z","iopub.status.idle":"2022-07-06T03:58:51.093037Z","shell.execute_reply.started":"2022-07-06T03:58:51.071890Z","shell.execute_reply":"2022-07-06T03:58:51.091816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-06T03:59:23.161531Z","iopub.execute_input":"2022-07-06T03:59:23.161929Z","iopub.status.idle":"2022-07-06T03:59:23.402947Z","shell.execute_reply.started":"2022-07-06T03:59:23.161897Z","shell.execute_reply":"2022-07-06T03:59:23.401815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['f_07'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:02:34.926344Z","iopub.execute_input":"2022-07-06T04:02:34.926799Z","iopub.status.idle":"2022-07-06T04:02:34.937673Z","shell.execute_reply.started":"2022-07-06T04:02:34.926737Z","shell.execute_reply":"2022-07-06T04:02:34.936688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:09:09.200645Z","iopub.execute_input":"2022-07-06T04:09:09.201198Z","iopub.status.idle":"2022-07-06T04:09:09.207339Z","shell.execute_reply.started":"2022-07-06T04:09:09.201148Z","shell.execute_reply":"2022-07-06T04:09:09.206013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scalar=StandardScaler()","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:09:34.180539Z","iopub.execute_input":"2022-07-06T04:09:34.180951Z","iopub.status.idle":"2022-07-06T04:09:34.186501Z","shell.execute_reply.started":"2022-07-06T04:09:34.180915Z","shell.execute_reply":"2022-07-06T04:09:34.185268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(['id'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:10:41.685908Z","iopub.execute_input":"2022-07-06T04:10:41.686985Z","iopub.status.idle":"2022-07-06T04:10:41.701162Z","shell.execute_reply.started":"2022-07-06T04:10:41.686932Z","shell.execute_reply":"2022-07-06T04:10:41.699823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scalar.fit(data)","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:11:08.361505Z","iopub.execute_input":"2022-07-06T04:11:08.362688Z","iopub.status.idle":"2022-07-06T04:11:08.413205Z","shell.execute_reply.started":"2022-07-06T04:11:08.362615Z","shell.execute_reply":"2022-07-06T04:11:08.412124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaled_data=scalar.transform(data)","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:12:07.175397Z","iopub.execute_input":"2022-07-06T04:12:07.175753Z","iopub.status.idle":"2022-07-06T04:12:07.199636Z","shell.execute_reply.started":"2022-07-06T04:12:07.175725Z","shell.execute_reply":"2022-07-06T04:12:07.198229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaled_data[0]","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:14:38.711466Z","iopub.execute_input":"2022-07-06T04:14:38.712000Z","iopub.status.idle":"2022-07-06T04:14:38.721672Z","shell.execute_reply.started":"2022-07-06T04:14:38.711953Z","shell.execute_reply":"2022-07-06T04:14:38.720463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.decomposition import PCA","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:16:02.754847Z","iopub.execute_input":"2022-07-06T04:16:02.755234Z","iopub.status.idle":"2022-07-06T04:16:02.931030Z","shell.execute_reply.started":"2022-07-06T04:16:02.755203Z","shell.execute_reply":"2022-07-06T04:16:02.929842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca=PCA(n_components=0.8)","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:22:15.212272Z","iopub.execute_input":"2022-07-06T04:22:15.212655Z","iopub.status.idle":"2022-07-06T04:22:15.217980Z","shell.execute_reply.started":"2022-07-06T04:22:15.212614Z","shell.execute_reply":"2022-07-06T04:22:15.217082Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca.fit(scaled_data)","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:22:15.356306Z","iopub.execute_input":"2022-07-06T04:22:15.356891Z","iopub.status.idle":"2022-07-06T04:22:15.482204Z","shell.execute_reply.started":"2022-07-06T04:22:15.356857Z","shell.execute_reply":"2022-07-06T04:22:15.481103Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t_data=pca.transform(scaled_data)","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:22:15.546664Z","iopub.execute_input":"2022-07-06T04:22:15.548610Z","iopub.status.idle":"2022-07-06T04:22:15.595021Z","shell.execute_reply.started":"2022-07-06T04:22:15.548525Z","shell.execute_reply":"2022-07-06T04:22:15.593629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t_data.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:22:15.809475Z","iopub.execute_input":"2022-07-06T04:22:15.810185Z","iopub.status.idle":"2022-07-06T04:22:15.817521Z","shell.execute_reply.started":"2022-07-06T04:22:15.810146Z","shell.execute_reply":"2022-07-06T04:22:15.816574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t_data[0]","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:22:18.203028Z","iopub.execute_input":"2022-07-06T04:22:18.203975Z","iopub.status.idle":"2022-07-06T04:22:18.210662Z","shell.execute_reply.started":"2022-07-06T04:22:18.203935Z","shell.execute_reply":"2022-07-06T04:22:18.209553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.cluster import KMeans","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:23:26.224597Z","iopub.execute_input":"2022-07-06T04:23:26.225027Z","iopub.status.idle":"2022-07-06T04:23:26.350286Z","shell.execute_reply.started":"2022-07-06T04:23:26.224992Z","shell.execute_reply":"2022-07-06T04:23:26.349246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kmeans = KMeans(n_clusters=5, random_state=0).fit(t_data)","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:26:28.153891Z","iopub.execute_input":"2022-07-06T04:26:28.154275Z","iopub.status.idle":"2022-07-06T04:26:31.871446Z","shell.execute_reply.started":"2022-07-06T04:26:28.154246Z","shell.execute_reply":"2022-07-06T04:26:31.870208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kmeans.labels_","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:26:31.873781Z","iopub.execute_input":"2022-07-06T04:26:31.874178Z","iopub.status.idle":"2022-07-06T04:26:31.884324Z","shell.execute_reply.started":"2022-07-06T04:26:31.874144Z","shell.execute_reply":"2022-07-06T04:26:31.881867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = kmeans.predict(t_data)","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:26:31.886824Z","iopub.execute_input":"2022-07-06T04:26:31.887966Z","iopub.status.idle":"2022-07-06T04:26:31.908545Z","shell.execute_reply.started":"2022-07-06T04:26:31.887917Z","shell.execute_reply":"2022-07-06T04:26:31.907605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:26:31.910882Z","iopub.execute_input":"2022-07-06T04:26:31.911619Z","iopub.status.idle":"2022-07-06T04:26:31.919590Z","shell.execute_reply.started":"2022-07-06T04:26:31.911569Z","shell.execute_reply":"2022-07-06T04:26:31.918390Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission['Predicted']=pred","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:27:55.019410Z","iopub.execute_input":"2022-07-06T04:27:55.019872Z","iopub.status.idle":"2022-07-06T04:27:55.026479Z","shell.execute_reply.started":"2022-07-06T04:27:55.019833Z","shell.execute_reply":"2022-07-06T04:27:55.025291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:27:59.912505Z","iopub.execute_input":"2022-07-06T04:27:59.913258Z","iopub.status.idle":"2022-07-06T04:27:59.926018Z","shell.execute_reply.started":"2022-07-06T04:27:59.913213Z","shell.execute_reply":"2022-07-06T04:27:59.924858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-06T04:28:51.182334Z","iopub.execute_input":"2022-07-06T04:28:51.182835Z","iopub.status.idle":"2022-07-06T04:28:51.346461Z","shell.execute_reply.started":"2022-07-06T04:28:51.182796Z","shell.execute_reply":"2022-07-06T04:28:51.345193Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}