{"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)\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport warnings\nwarnings.filterwarnings('ignore')\n\nfrom sklearn.metrics import confusion_matrix,accuracy_score","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-08-09T07:45:33.667642Z","iopub.execute_input":"2021-08-09T07:45:33.668199Z","iopub.status.idle":"2021-08-09T07:45:33.674533Z","shell.execute_reply.started":"2021-08-09T07:45:33.668151Z","shell.execute_reply":"2021-08-09T07:45:33.673324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv('/kaggle/input/siim-covid19-detection/train_study_level.csv')\ndf","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:33.979881Z","iopub.execute_input":"2021-08-09T07:45:33.980303Z","iopub.status.idle":"2021-08-09T07:45:34.007946Z","shell.execute_reply.started":"2021-08-09T07:45:33.980265Z","shell.execute_reply":"2021-08-09T07:45:34.007205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:34.884801Z","iopub.execute_input":"2021-08-09T07:45:34.885423Z","iopub.status.idle":"2021-08-09T07:45:34.895218Z","shell.execute_reply.started":"2021-08-09T07:45:34.885385Z","shell.execute_reply":"2021-08-09T07:45:34.894135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:35.294782Z","iopub.execute_input":"2021-08-09T07:45:35.295270Z","iopub.status.idle":"2021-08-09T07:45:35.320965Z","shell.execute_reply.started":"2021-08-09T07:45:35.295238Z","shell.execute_reply":"2021-08-09T07:45:35.320226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:35.916992Z","iopub.execute_input":"2021-08-09T07:45:35.917478Z","iopub.status.idle":"2021-08-09T07:45:35.931509Z","shell.execute_reply.started":"2021-08-09T07:45:35.917445Z","shell.execute_reply":"2021-08-09T07:45:35.930698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = df.iloc[:,1:4]\ny = df.iloc[:,[4]]","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:36.287206Z","iopub.execute_input":"2021-08-09T07:45:36.287725Z","iopub.status.idle":"2021-08-09T07:45:36.293013Z","shell.execute_reply.started":"2021-08-09T07:45:36.287691Z","shell.execute_reply":"2021-08-09T07:45:36.291951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.shape,y.shape","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:36.629303Z","iopub.execute_input":"2021-08-09T07:45:36.629699Z","iopub.status.idle":"2021-08-09T07:45:36.635852Z","shell.execute_reply.started":"2021-08-09T07:45:36.629668Z","shell.execute_reply":"2021-08-09T07:45:36.634769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,5))\nplt.subplot(1,2,1)\nsns.countplot(df['Negative for Pneumonia'])\n\nplt.subplot(1,2,2)\nsns.countplot(df['Typical Appearance'])","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:36.914605Z","iopub.execute_input":"2021-08-09T07:45:36.914948Z","iopub.status.idle":"2021-08-09T07:45:37.167447Z","shell.execute_reply.started":"2021-08-09T07:45:36.914918Z","shell.execute_reply":"2021-08-09T07:45:37.166415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.pairplot(x,kind='scatter')","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:37.218698Z","iopub.execute_input":"2021-08-09T07:45:37.219070Z","iopub.status.idle":"2021-08-09T07:45:39.457972Z","shell.execute_reply.started":"2021-08-09T07:45:37.219033Z","shell.execute_reply":"2021-08-09T07:45:39.456874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nx_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.2,random_state=57)\nprint('X_train shape = ',x_train.shape)\nprint('X_test shape = ',x_test.shape)\nprint('Y_train shape = ',y_train.shape)\nprint('Y_test shape = ',y_test.shape)\n","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:39.459915Z","iopub.execute_input":"2021-08-09T07:45:39.460351Z","iopub.status.idle":"2021-08-09T07:45:39.473249Z","shell.execute_reply.started":"2021-08-09T07:45:39.460304Z","shell.execute_reply":"2021-08-09T07:45:39.472402Z"},"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(x_test)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:39.475296Z","iopub.execute_input":"2021-08-09T07:45:39.475643Z","iopub.status.idle":"2021-08-09T07:45:39.494428Z","shell.execute_reply.started":"2021-08-09T07:45:39.475610Z","shell.execute_reply":"2021-08-09T07:45:39.493271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.tree import DecisionTreeClassifier\ndtc = DecisionTreeClassifier(criterion='gini',random_state=56)\ndtc.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:39.496138Z","iopub.execute_input":"2021-08-09T07:45:39.496467Z","iopub.status.idle":"2021-08-09T07:45:39.516153Z","shell.execute_reply.started":"2021-08-09T07:45:39.496436Z","shell.execute_reply":"2021-08-09T07:45:39.514721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_dtc = dtc.predict(x_test)\ny_pred_dtc","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:39.517631Z","iopub.execute_input":"2021-08-09T07:45:39.517933Z","iopub.status.idle":"2021-08-09T07:45:39.529940Z","shell.execute_reply.started":"2021-08-09T07:45:39.517904Z","shell.execute_reply":"2021-08-09T07:45:39.528313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(confusion_matrix(y_test,y_pred_dtc))\nprint(accuracy_score(y_test,y_pred_dtc)*100)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:39.531307Z","iopub.execute_input":"2021-08-09T07:45:39.531632Z","iopub.status.idle":"2021-08-09T07:45:39.547389Z","shell.execute_reply.started":"2021-08-09T07:45:39.531574Z","shell.execute_reply":"2021-08-09T07:45:39.545966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Random Forest Classifier\nfrom sklearn.ensemble import RandomForestClassifier\nrfc = RandomForestClassifier(n_estimators=100,criterion='gini',random_state=55)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:39.740836Z","iopub.execute_input":"2021-08-09T07:45:39.741234Z","iopub.status.idle":"2021-08-09T07:45:39.746721Z","shell.execute_reply.started":"2021-08-09T07:45:39.741198Z","shell.execute_reply":"2021-08-09T07:45:39.745673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rfc.fit(x_train,y_train)\ny_pred_rfc = rfc.predict(x_test) ","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:40.209032Z","iopub.execute_input":"2021-08-09T07:45:40.209399Z","iopub.status.idle":"2021-08-09T07:45:40.471566Z","shell.execute_reply.started":"2021-08-09T07:45:40.209369Z","shell.execute_reply":"2021-08-09T07:45:40.470547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(confusion_matrix(y_test,y_pred_rfc))\nprint(accuracy_score(y_test,y_pred_rfc)*100)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:40.734463Z","iopub.execute_input":"2021-08-09T07:45:40.734833Z","iopub.status.idle":"2021-08-09T07:45:40.744093Z","shell.execute_reply.started":"2021-08-09T07:45:40.734803Z","shell.execute_reply":"2021-08-09T07:45:40.743215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Logistic Regression \nfrom sklearn.linear_model import LogisticRegression\n\nlr = LogisticRegression(random_state=55)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:41.297835Z","iopub.execute_input":"2021-08-09T07:45:41.298204Z","iopub.status.idle":"2021-08-09T07:45:41.302386Z","shell.execute_reply.started":"2021-08-09T07:45:41.298171Z","shell.execute_reply":"2021-08-09T07:45:41.301528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lr.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:41.949627Z","iopub.execute_input":"2021-08-09T07:45:41.950314Z","iopub.status.idle":"2021-08-09T07:45:42.035224Z","shell.execute_reply.started":"2021-08-09T07:45:41.950268Z","shell.execute_reply":"2021-08-09T07:45:42.033931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_lr = lr.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:42.536522Z","iopub.execute_input":"2021-08-09T07:45:42.536904Z","iopub.status.idle":"2021-08-09T07:45:42.543266Z","shell.execute_reply.started":"2021-08-09T07:45:42.536873Z","shell.execute_reply":"2021-08-09T07:45:42.541769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(confusion_matrix(y_test,y_pred_lr))\nprint(accuracy_score(y_test,y_pred_lr)*100)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:42.978213Z","iopub.execute_input":"2021-08-09T07:45:42.978563Z","iopub.status.idle":"2021-08-09T07:45:42.987341Z","shell.execute_reply.started":"2021-08-09T07:45:42.978532Z","shell.execute_reply":"2021-08-09T07:45:42.986539Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Support Vector Classification\nfrom sklearn.svm import SVC\nsv = SVC(kernel='rbf',random_state=55)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:43.509931Z","iopub.execute_input":"2021-08-09T07:45:43.510439Z","iopub.status.idle":"2021-08-09T07:45:43.515565Z","shell.execute_reply.started":"2021-08-09T07:45:43.510405Z","shell.execute_reply":"2021-08-09T07:45:43.514423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sv.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:43.980478Z","iopub.execute_input":"2021-08-09T07:45:43.980874Z","iopub.status.idle":"2021-08-09T07:45:43.997159Z","shell.execute_reply.started":"2021-08-09T07:45:43.980836Z","shell.execute_reply":"2021-08-09T07:45:43.995805Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_sv = sv.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:44.491778Z","iopub.execute_input":"2021-08-09T07:45:44.492266Z","iopub.status.idle":"2021-08-09T07:45:44.497341Z","shell.execute_reply.started":"2021-08-09T07:45:44.492233Z","shell.execute_reply":"2021-08-09T07:45:44.496358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(confusion_matrix(y_test,y_pred_sv))\nprint(accuracy_score(y_test,y_pred_sv)*100)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:45.030746Z","iopub.execute_input":"2021-08-09T07:45:45.031098Z","iopub.status.idle":"2021-08-09T07:45:45.040887Z","shell.execute_reply.started":"2021-08-09T07:45:45.031069Z","shell.execute_reply":"2021-08-09T07:45:45.040008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# K Nearest Neighbour Classifier\nfrom sklearn.neighbors import KNeighborsClassifier\nknc = KNeighborsClassifier(n_neighbors=7)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:45.492641Z","iopub.execute_input":"2021-08-09T07:45:45.493024Z","iopub.status.idle":"2021-08-09T07:45:45.498005Z","shell.execute_reply.started":"2021-08-09T07:45:45.492990Z","shell.execute_reply":"2021-08-09T07:45:45.497043Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"knc.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:45.934951Z","iopub.execute_input":"2021-08-09T07:45:45.935329Z","iopub.status.idle":"2021-08-09T07:45:45.964070Z","shell.execute_reply.started":"2021-08-09T07:45:45.935296Z","shell.execute_reply":"2021-08-09T07:45:45.963311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_knc = knc.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:46.367172Z","iopub.execute_input":"2021-08-09T07:45:46.367751Z","iopub.status.idle":"2021-08-09T07:45:46.442993Z","shell.execute_reply.started":"2021-08-09T07:45:46.367697Z","shell.execute_reply":"2021-08-09T07:45:46.442108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(confusion_matrix(y_test,y_pred_knc))\nprint(accuracy_score(y_test,y_pred_knc)*100)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:46.901546Z","iopub.execute_input":"2021-08-09T07:45:46.902067Z","iopub.status.idle":"2021-08-09T07:45:46.910779Z","shell.execute_reply.started":"2021-08-09T07:45:46.902021Z","shell.execute_reply":"2021-08-09T07:45:46.909820Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Naive Bayes Classifier\nfrom sklearn.naive_bayes import GaussianNB\nnb = GaussianNB()","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:47.343711Z","iopub.execute_input":"2021-08-09T07:45:47.344095Z","iopub.status.idle":"2021-08-09T07:45:47.349076Z","shell.execute_reply.started":"2021-08-09T07:45:47.344057Z","shell.execute_reply":"2021-08-09T07:45:47.347966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nb.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:47.844961Z","iopub.execute_input":"2021-08-09T07:45:47.845403Z","iopub.status.idle":"2021-08-09T07:45:47.853279Z","shell.execute_reply.started":"2021-08-09T07:45:47.845367Z","shell.execute_reply":"2021-08-09T07:45:47.852514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_nb = nb.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:48.240398Z","iopub.execute_input":"2021-08-09T07:45:48.240931Z","iopub.status.idle":"2021-08-09T07:45:48.245473Z","shell.execute_reply.started":"2021-08-09T07:45:48.240895Z","shell.execute_reply":"2021-08-09T07:45:48.244564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(confusion_matrix(y_test,y_pred_nb))\nprint(accuracy_score(y_test,y_pred_nb)*100)","metadata":{"execution":{"iopub.status.busy":"2021-08-09T07:45:48.714129Z","iopub.execute_input":"2021-08-09T07:45:48.714641Z","iopub.status.idle":"2021-08-09T07:45:48.724034Z","shell.execute_reply.started":"2021-08-09T07:45:48.714605Z","shell.execute_reply":"2021-08-09T07:45:48.722753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}