{"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":"# Import libs","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom sklearn.naive_bayes import GaussianNB\nfrom sklearn.preprocessing import LabelEncoder\nfrom matplotlib import ticker\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.preprocessing import LabelEncoder\nimport seaborn as sns\nimport warnings\n\n# options\nwarnings.filterwarnings('ignore')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-18T15:27:34.950337Z","iopub.execute_input":"2022-07-18T15:27:34.951141Z","iopub.status.idle":"2022-07-18T15:27:35.677478Z","shell.execute_reply.started":"2022-07-18T15:27:34.951019Z","shell.execute_reply":"2022-07-18T15:27:35.676026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Import Dataset","metadata":{}},{"cell_type":"code","source":"train = pd.read_csv('../input/devday22-competition-datascience/train.csv')\ntest = pd.read_csv('../input/devday22-competition-datascience/test.csv')\nsubmission = pd.read_csv('../input/devday22-competition-datascience/sample_submission.csv')\n","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:35.679032Z","iopub.execute_input":"2022-07-18T15:27:35.679404Z","iopub.status.idle":"2022-07-18T15:27:38.101042Z","shell.execute_reply.started":"2022-07-18T15:27:35.679365Z","shell.execute_reply":"2022-07-18T15:27:38.098980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Analysis","metadata":{}},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:38.103287Z","iopub.execute_input":"2022-07-18T15:27:38.103768Z","iopub.status.idle":"2022-07-18T15:27:38.139359Z","shell.execute_reply.started":"2022-07-18T15:27:38.103726Z","shell.execute_reply":"2022-07-18T15:27:38.138381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:38.144307Z","iopub.execute_input":"2022-07-18T15:27:38.144905Z","iopub.status.idle":"2022-07-18T15:27:38.180484Z","shell.execute_reply.started":"2022-07-18T15:27:38.144850Z","shell.execute_reply":"2022-07-18T15:27:38.178716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(1,10):\n    print('Sequence : ',i,train.iloc[:,i].unique())\n","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:38.182190Z","iopub.execute_input":"2022-07-18T15:27:38.182625Z","iopub.status.idle":"2022-07-18T15:27:38.324271Z","shell.execute_reply.started":"2022-07-18T15:27:38.182588Z","shell.execute_reply":"2022-07-18T15:27:38.322552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:38.326616Z","iopub.execute_input":"2022-07-18T15:27:38.327503Z","iopub.status.idle":"2022-07-18T15:27:38.521310Z","shell.execute_reply.started":"2022-07-18T15:27:38.327412Z","shell.execute_reply":"2022-07-18T15:27:38.519374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:38.522733Z","iopub.execute_input":"2022-07-18T15:27:38.523076Z","iopub.status.idle":"2022-07-18T15:27:38.532696Z","shell.execute_reply.started":"2022-07-18T15:27:38.523043Z","shell.execute_reply":"2022-07-18T15:27:38.530676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:38.535388Z","iopub.execute_input":"2022-07-18T15:27:38.535954Z","iopub.status.idle":"2022-07-18T15:27:38.674809Z","shell.execute_reply.started":"2022-07-18T15:27:38.535907Z","shell.execute_reply":"2022-07-18T15:27:38.673615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Corr = train.drop('ID',axis=1).select_dtypes(exclude=[\"object\"]).corr()\nabs_corr_on_saleprice = abs(Corr[['mutation']].copy())\nabs_corr_on_saleprice.drop('mutation', axis=0, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:38.676419Z","iopub.execute_input":"2022-07-18T15:27:38.676817Z","iopub.status.idle":"2022-07-18T15:27:38.997554Z","shell.execute_reply.started":"2022-07-18T15:27:38.676782Z","shell.execute_reply":"2022-07-18T15:27:38.996308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"abs_corr_on_saleprice.sort_values(by='mutation', ascending=False).plot(kind='bar', figsize=(12,8))\nplt.xticks(rotation=45)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:38.999719Z","iopub.execute_input":"2022-07-18T15:27:39.000540Z","iopub.status.idle":"2022-07-18T15:27:39.329489Z","shell.execute_reply.started":"2022-07-18T15:27:39.000487Z","shell.execute_reply":"2022-07-18T15:27:39.328097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le=LabelEncoder()\nfor col in train.drop('ID',axis=1).columns:\n    if train[col].dtypes == object:\n        train[col]= le.fit_transform(train[col])\n\n\n\nfor col in test.drop('ID',axis=1).columns:\n    if test[col].dtypes == object:\n        test[col]= le.fit_transform(test[col])","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:39.330987Z","iopub.execute_input":"2022-07-18T15:27:39.331352Z","iopub.status.idle":"2022-07-18T15:27:40.330682Z","shell.execute_reply.started":"2022-07-18T15:27:39.331317Z","shell.execute_reply":"2022-07-18T15:27:40.329384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:40.332710Z","iopub.execute_input":"2022-07-18T15:27:40.333807Z","iopub.status.idle":"2022-07-18T15:27:40.360777Z","shell.execute_reply.started":"2022-07-18T15:27:40.333751Z","shell.execute_reply":"2022-07-18T15:27:40.359242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:40.366172Z","iopub.execute_input":"2022-07-18T15:27:40.366593Z","iopub.status.idle":"2022-07-18T15:27:40.396113Z","shell.execute_reply.started":"2022-07-18T15:27:40.366557Z","shell.execute_reply":"2022-07-18T15:27:40.394949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = train.drop([\"mutation\",\"ID\"], axis=1)\nY_train = train[\"mutation\"]","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:40.398200Z","iopub.execute_input":"2022-07-18T15:27:40.398799Z","iopub.status.idle":"2022-07-18T15:27:40.443962Z","shell.execute_reply.started":"2022-07-18T15:27:40.398756Z","shell.execute_reply":"2022-07-18T15:27:40.442733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape,Y_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:40.445513Z","iopub.execute_input":"2022-07-18T15:27:40.446039Z","iopub.status.idle":"2022-07-18T15:27:40.453897Z","shell.execute_reply.started":"2022-07-18T15:27:40.445988Z","shell.execute_reply":"2022-07-18T15:27:40.452838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\nsc = StandardScaler()\nX_train = sc.fit_transform(X_train)\nX_test = sc.transform(test.drop('ID',axis=1))","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:40.455299Z","iopub.execute_input":"2022-07-18T15:27:40.455749Z","iopub.status.idle":"2022-07-18T15:27:40.648520Z","shell.execute_reply.started":"2022-07-18T15:27:40.455711Z","shell.execute_reply":"2022-07-18T15:27:40.647101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:40.649966Z","iopub.execute_input":"2022-07-18T15:27:40.650333Z","iopub.status.idle":"2022-07-18T15:27:40.660003Z","shell.execute_reply.started":"2022-07-18T15:27:40.650298Z","shell.execute_reply":"2022-07-18T15:27:40.658559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:40.661551Z","iopub.execute_input":"2022-07-18T15:27:40.661980Z","iopub.status.idle":"2022-07-18T15:27:40.677885Z","shell.execute_reply.started":"2022-07-18T15:27:40.661945Z","shell.execute_reply":"2022-07-18T15:27:40.676736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Apply PCA","metadata":{}},{"cell_type":"code","source":"from sklearn.decomposition import PCA\npca = PCA(n_components = 2)\nX_train = pca.fit_transform(X_train)\nX_test = pca.transform(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:40.680667Z","iopub.execute_input":"2022-07-18T15:27:40.681479Z","iopub.status.idle":"2022-07-18T15:27:42.181213Z","shell.execute_reply.started":"2022-07-18T15:27:40.681362Z","shell.execute_reply":"2022-07-18T15:27:42.179823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:42.183417Z","iopub.execute_input":"2022-07-18T15:27:42.184471Z","iopub.status.idle":"2022-07-18T15:27:42.195541Z","shell.execute_reply.started":"2022-07-18T15:27:42.184394Z","shell.execute_reply":"2022-07-18T15:27:42.193819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:42.198478Z","iopub.execute_input":"2022-07-18T15:27:42.200038Z","iopub.status.idle":"2022-07-18T15:27:42.215147Z","shell.execute_reply.started":"2022-07-18T15:27:42.199967Z","shell.execute_reply":"2022-07-18T15:27:42.212284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Gaussian NB","metadata":{}},{"cell_type":"code","source":"from sklearn.naive_bayes import GaussianNB\nmodel=GaussianNB()\nmodel.fit(X_train,Y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:42.218669Z","iopub.execute_input":"2022-07-18T15:27:42.220039Z","iopub.status.idle":"2022-07-18T15:27:42.315834Z","shell.execute_reply.started":"2022-07-18T15:27:42.219858Z","shell.execute_reply":"2022-07-18T15:27:42.314585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = model.predict_proba(X_test)\npred = pred[:, 1]\npred","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:42.317162Z","iopub.execute_input":"2022-07-18T15:27:42.317661Z","iopub.status.idle":"2022-07-18T15:27:42.346542Z","shell.execute_reply.started":"2022-07-18T15:27:42.317616Z","shell.execute_reply":"2022-07-18T15:27:42.345552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission['mutation'] = pred\nsubmission.to_csv('submission1.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:42.348715Z","iopub.execute_input":"2022-07-18T15:27:42.349182Z","iopub.status.idle":"2022-07-18T15:27:42.781721Z","shell.execute_reply.started":"2022-07-18T15:27:42.349144Z","shell.execute_reply":"2022-07-18T15:27:42.780278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Random Forest","metadata":{}},{"cell_type":"code","source":"random_forest = RandomForestClassifier(n_estimators=100)\nrandom_forest.fit(X_train, Y_train)\npred = random_forest.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:27:42.783920Z","iopub.execute_input":"2022-07-18T15:27:42.784613Z","iopub.status.idle":"2022-07-18T15:28:38.813081Z","shell.execute_reply.started":"2022-07-18T15:27:42.784574Z","shell.execute_reply":"2022-07-18T15:28:38.811735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"random_forest.score(X_train, Y_train)\nacc_random_forest = round(random_forest.score(X_train, Y_train) * 100, 2)\nacc_random_forest","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:28:38.814622Z","iopub.execute_input":"2022-07-18T15:28:38.814995Z","iopub.status.idle":"2022-07-18T15:28:54.117507Z","shell.execute_reply.started":"2022-07-18T15:28:38.814959Z","shell.execute_reply":"2022-07-18T15:28:54.115889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission['mutation'] = pred\nsubmission.to_csv('submission2.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T15:28:54.119678Z","iopub.execute_input":"2022-07-18T15:28:54.120205Z","iopub.status.idle":"2022-07-18T15:28:54.328136Z","shell.execute_reply.started":"2022-07-18T15:28:54.120155Z","shell.execute_reply":"2022-07-18T15:28:54.326758Z"},"trusted":true},"execution_count":null,"outputs":[]}]}