{"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":"#BASIC\nimport numpy as np \nimport pandas as pd \nimport os\n\n# DATA visualization\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport PIL\nfrom IPython.display import Image, display\nfrom plotly import graph_objs as go\nimport plotly.express as px\nimport plotly.figure_factory as ff\n\nimport openslide","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:21:41.879027Z","iopub.execute_input":"2022-11-15T18:21:41.879412Z","iopub.status.idle":"2022-11-15T18:21:41.885979Z","shell.execute_reply.started":"2022-11-15T18:21:41.879381Z","shell.execute_reply":"2022-11-15T18:21:41.884722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BASE_FOLDER = \"/kaggle/input/prostate-cancer-grade-assessment/\"\n!ls {BASE_FOLDER}","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:21:55.224114Z","iopub.execute_input":"2022-11-15T18:21:55.224523Z","iopub.status.idle":"2022-11-15T18:21:56.351305Z","shell.execute_reply.started":"2022-11-15T18:21:55.224492Z","shell.execute_reply":"2022-11-15T18:21:56.349823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mask_dir = f'{BASE_FOLDER}/train_label_masks'","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:22:15.2798Z","iopub.execute_input":"2022-11-15T18:22:15.280238Z","iopub.status.idle":"2022-11-15T18:22:15.286155Z","shell.execute_reply.started":"2022-11-15T18:22:15.280202Z","shell.execute_reply":"2022-11-15T18:22:15.284721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(BASE_FOLDER+\"train.csv\")\ntest = pd.read_csv(BASE_FOLDER+\"test.csv\")\nsub = pd.read_csv(BASE_FOLDER+\"sample_submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:22:30.694758Z","iopub.execute_input":"2022-11-15T18:22:30.695187Z","iopub.status.idle":"2022-11-15T18:22:30.752695Z","shell.execute_reply.started":"2022-11-15T18:22:30.695152Z","shell.execute_reply":"2022-11-15T18:22:30.751437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:22:41.268561Z","iopub.execute_input":"2022-11-15T18:22:41.268966Z","iopub.status.idle":"2022-11-15T18:22:41.281386Z","shell.execute_reply.started":"2022-11-15T18:22:41.268934Z","shell.execute_reply":"2022-11-15T18:22:41.280461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop([7273],inplace=True) #Mislabelled","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:22:59.040618Z","iopub.execute_input":"2022-11-15T18:22:59.041074Z","iopub.status.idle":"2022-11-15T18:22:59.049534Z","shell.execute_reply.started":"2022-11-15T18:22:59.041043Z","shell.execute_reply":"2022-11-15T18:22:59.048129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['gleason_score'] = train['gleason_score'].apply(lambda x: \"0+0\" if x==\"negative\" else x)","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:23:12.787427Z","iopub.execute_input":"2022-11-15T18:23:12.787857Z","iopub.status.idle":"2022-11-15T18:23:12.796594Z","shell.execute_reply.started":"2022-11-15T18:23:12.787822Z","shell.execute_reply":"2022-11-15T18:23:12.795526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = train.groupby('isup_grade').count()['image_id'].reset_index().sort_values(by='image_id',ascending=False)\ntemp.style.background_gradient(cmap='Purples')","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:23:27.982065Z","iopub.execute_input":"2022-11-15T18:23:27.982509Z","iopub.status.idle":"2022-11-15T18:23:28.071183Z","shell.execute_reply.started":"2022-11-15T18:23:27.982473Z","shell.execute_reply":"2022-11-15T18:23:28.069132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = go.Figure(go.Funnelarea(\n    text =temp.isup_grade,\n    values = temp.image_id,\n    title = {\"position\": \"top center\", \"text\": \"Funnel-Chart of ISUP_grade Distribution\"}\n    ))\nfig.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:23:49.537617Z","iopub.execute_input":"2022-11-15T18:23:49.538491Z","iopub.status.idle":"2022-11-15T18:23:49.629527Z","shell.execute_reply.started":"2022-11-15T18:23:49.538449Z","shell.execute_reply":"2022-11-15T18:23:49.628301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.bar(temp, x='isup_grade', y='image_id',\n             hover_data=['image_id', 'isup_grade'], color='image_id',\n             labels={'pop':'population of Canada'}, height=400)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:24:08.157835Z","iopub.execute_input":"2022-11-15T18:24:08.158266Z","iopub.status.idle":"2022-11-15T18:24:09.148878Z","shell.execute_reply.started":"2022-11-15T18:24:08.158228Z","shell.execute_reply":"2022-11-15T18:24:09.147952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = plt.figure(figsize=(10,6))\nax = sns.countplot(x=\"isup_grade\", hue=\"data_provider\", data=train)\nfor p in ax.patches:\n    height = p.get_height()\n    ax.text(p.get_x()+p.get_width()/2,\n                height +3,\n                '{:1.2f}%'.format(100*height/10616),\n                ha=\"center\")","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:24:25.669506Z","iopub.execute_input":"2022-11-15T18:24:25.669929Z","iopub.status.idle":"2022-11-15T18:24:26.09819Z","shell.execute_reply.started":"2022-11-15T18:24:25.669895Z","shell.execute_reply":"2022-11-15T18:24:26.096975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = train.groupby('gleason_score').count()['image_id'].reset_index().sort_values(by='image_id',ascending=False)\ntemp.style.background_gradient(cmap='Reds')","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:24:39.487758Z","iopub.execute_input":"2022-11-15T18:24:39.488219Z","iopub.status.idle":"2022-11-15T18:24:39.512933Z","shell.execute_reply.started":"2022-11-15T18:24:39.488184Z","shell.execute_reply":"2022-11-15T18:24:39.51197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = go.Figure(go.Funnelarea(\n    text =temp.gleason_score,\n    values = temp.image_id,\n    title = {\"position\": \"top center\", \"text\": \"Funnel-Chart of ISUP_grade Distribution\"}\n    ))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:24:53.632729Z","iopub.execute_input":"2022-11-15T18:24:53.633135Z","iopub.status.idle":"2022-11-15T18:24:53.646421Z","shell.execute_reply.started":"2022-11-15T18:24:53.633101Z","shell.execute_reply":"2022-11-15T18:24:53.645074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.bar(temp, x='gleason_score', y='image_id',\n             hover_data=['image_id', 'gleason_score'], color='image_id',\n             labels={'pop':'population of Canada'}, height=400)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:25:33.917884Z","iopub.execute_input":"2022-11-15T18:25:33.918409Z","iopub.status.idle":"2022-11-15T18:25:33.987223Z","shell.execute_reply.started":"2022-11-15T18:25:33.918366Z","shell.execute_reply":"2022-11-15T18:25:33.986121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"'''\nVisualizing the GLEASON_SCORE distribution wrt Data_providers\n'''\n\nfig = plt.figure(figsize=(10,6))\nax = sns.countplot(x=\"gleason_score\", hue=\"data_provider\", data=train)\nfor p in ax.patches:\n    height = p.get_height()\n    ax.text(p.get_x()+p.get_width()/2.,\n                height + 3,\n                '{:1.2f}%'.format(100*height/10616),\n                ha=\"center\")","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:26:18.843926Z","iopub.execute_input":"2022-11-15T18:26:18.844341Z","iopub.status.idle":"2022-11-15T18:26:19.254823Z","shell.execute_reply.started":"2022-11-15T18:26:18.844307Z","shell.execute_reply":"2022-11-15T18:26:19.253476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Open the image (does not yet read the image into memory)\nexample = openslide.OpenSlide(os.path.join(BASE_FOLDER+\"train_images\", '005e66f06bce9c2e49142536caf2f6ee.tiff'))\n\n# Read a specific region of the image starting at upper left coordinate (x=17800, y=19500) on level 0 and extracting a 256*256 pixel patch.\n# At this point image data is read from the file and loaded into memory.\npatch = example.read_region((17800,19500), 0, (256, 256))\n\n# Display the image\ndisplay(patch)\n\n# Close the opened slide after use\nexample.close()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:26:51.041952Z","iopub.execute_input":"2022-11-15T18:26:51.042378Z","iopub.status.idle":"2022-11-15T18:26:51.209014Z","shell.execute_reply.started":"2022-11-15T18:26:51.042346Z","shell.execute_reply":"2022-11-15T18:26:51.207933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.set_index('image_id')\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:27:08.214931Z","iopub.execute_input":"2022-11-15T18:27:08.215372Z","iopub.status.idle":"2022-11-15T18:27:08.229966Z","shell.execute_reply.started":"2022-11-15T18:27:08.215335Z","shell.execute_reply":"2022-11-15T18:27:08.228556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_values(image,max_size=(600,400)):\n    slide = openslide.OpenSlide(os.path.join(BASE_FOLDER+\"train_images\", f'{image}.tiff'))\n    \n    # Here we compute the \"pixel spacing\": the physical size of a pixel in the image.\n    # OpenSlide gives the resolution in centimeters so we convert this to microns.\n    f,ax =  plt.subplots(2 ,figsize=(6,16))\n    spacing = 1 / (float(slide.properties['tiff.XResolution']) / 10000)\n    patch = slide.read_region((1780,1950), 0, (256, 256)) #ZOOMED FUGURE\n    ax[0].imshow(patch) \n    ax[0].set_title('Zoomed Image')\n    ax[1].imshow(slide.get_thumbnail(size=max_size)) #UNZOOMED FIGURE\n    ax[1].set_title('Full Image')\n    \n    \n    print(f\"File id: {slide}\")\n    print(f\"Dimensions: {slide.dimensions}\")\n    print(f\"Microns per pixel / pixel spacing: {spacing:.3f}\")\n    print(f\"Number of levels in the image: {slide.level_count}\")\n    print(f\"Downsample factor per level: {slide.level_downsamples}\")\n    print(f\"Dimensions of levels: {slide.level_dimensions}\\n\\n\")\n    print(f\"ISUP grade: {train.loc[image, 'isup_grade']}\")\n    print(f\"Gleason score: {train.loc[image, 'gleason_score']}\")","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:27:48.0137Z","iopub.execute_input":"2022-11-15T18:27:48.014215Z","iopub.status.idle":"2022-11-15T18:27:48.031237Z","shell.execute_reply.started":"2022-11-15T18:27:48.014172Z","shell.execute_reply":"2022-11-15T18:27:48.02907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"get_values('07a7ef0ba3bb0d6564a73f4f3e1c2293')","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:28:05.9319Z","iopub.execute_input":"2022-11-15T18:28:05.932304Z","iopub.status.idle":"2022-11-15T18:28:06.805022Z","shell.execute_reply.started":"2022-11-15T18:28:05.932273Z","shell.execute_reply":"2022-11-15T18:28:06.804117Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def display_images(images):\n    '''\n    This function takes in input a list of images. It then iterates through the image making openslide objects , on which different functions\n    for getting out information can be called later\n    '''\n    f, ax = plt.subplots(5,3, figsize=(18,22))\n    for i, image in enumerate(images):\n        slide = openslide.OpenSlide(os.path.join(BASE_FOLDER+\"train_images\", f'{image}.tiff'))\n        # Making Openslide Object\n        #Here we compute the \"pixel spacing\": the physical size of a pixel in the image,\n        #OpenSlide gives the resolution in centimeters so we convert this to microns\n        spacing = 1/(float(slide.properties['tiff.XResolution']) / 10000)\n        patch = slide.read_region((1780,1950), 0, (256, 256)) #Reading the image as before betweeen x=1780 to y=1950 and of pixel size =256*256\n        ax[i//3, i%3].imshow(patch) #Displaying Image\n        slide.close()       \n        ax[i//3, i%3].axis('off')\n        image_id = image\n        data_provider = train.loc[image, 'data_provider']\n        isup_grade = train.loc[image, 'isup_grade']\n        gleason_score = train.loc[image, 'gleason_score']\n        ax[i//3, i%3].set_title(f\"ID: {image_id}\\nSource: {data_provider} ISUP: {isup_grade} Gleason: {gleason_score}\")\n\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:31:35.451262Z","iopub.execute_input":"2022-11-15T18:31:35.451746Z","iopub.status.idle":"2022-11-15T18:31:35.463623Z","shell.execute_reply.started":"2022-11-15T18:31:35.451705Z","shell.execute_reply":"2022-11-15T18:31:35.461704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images = [\n'07a7ef0ba3bb0d6564a73f4f3e1c2293',\n    '037504061b9fba71ef6e24c48c6df44d',\n    '035b1edd3d1aeeffc77ce5d248a01a53',\n    '059cbf902c5e42972587c8d17d49efed',\n    '06a0cbd8fd6320ef1aa6f19342af2e68',\n    '06eda4a6faca84e84a781fee2d5f47e1',\n    '0a4b7a7499ed55c71033cefb0765e93d',\n    '0838c82917cd9af681df249264d2769c',\n    '046b35ae95374bfb48cdca8d7c83233f',\n    '074c3e01525681a275a42282cd21cbde',\n    '05abe25c883d508ecc15b6e857e59f32',\n    '05f4e9415af9fdabc19109c980daf5ad',\n    '060121a06476ef401d8a21d6567dee6d',\n    '068b0e3be4c35ea983f77accf8351cc8',\n    '08f055372c7b8a7e1df97c6586542ac8'\n]\ndisplay_images(images)","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:32:04.884939Z","iopub.execute_input":"2022-11-15T18:32:04.885442Z","iopub.status.idle":"2022-11-15T18:32:07.636411Z","shell.execute_reply.started":"2022-11-15T18:32:04.885397Z","shell.execute_reply":"2022-11-15T18:32:07.635414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\ndata=pd.read_csv('../input/prostate-cancer/Prostate_Cancer.csv')\ndata.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:32:39.613627Z","iopub.execute_input":"2022-11-15T18:32:39.614052Z","iopub.status.idle":"2022-11-15T18:32:39.635235Z","shell.execute_reply.started":"2022-11-15T18:32:39.61402Z","shell.execute_reply":"2022-11-15T18:32:39.633916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.info()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:32:56.559828Z","iopub.execute_input":"2022-11-15T18:32:56.561116Z","iopub.status.idle":"2022-11-15T18:32:56.575908Z","shell.execute_reply.started":"2022-11-15T18:32:56.561063Z","shell.execute_reply":"2022-11-15T18:32:56.574675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=data.drop_duplicates()\ndata.info()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:33:14.160839Z","iopub.execute_input":"2022-11-15T18:33:14.16209Z","iopub.status.idle":"2022-11-15T18:33:14.178138Z","shell.execute_reply.started":"2022-11-15T18:33:14.162042Z","shell.execute_reply":"2022-11-15T18:33:14.176766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nenc=LabelEncoder()\ndata['diagnosis_result']=enc.fit_transform(data['diagnosis_result'])\ndata.info()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:33:26.275011Z","iopub.execute_input":"2022-11-15T18:33:26.275475Z","iopub.status.idle":"2022-11-15T18:33:26.294988Z","shell.execute_reply.started":"2022-11-15T18:33:26.275436Z","shell.execute_reply":"2022-11-15T18:33:26.293141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.describe()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:33:45.34412Z","iopub.execute_input":"2022-11-15T18:33:45.344527Z","iopub.status.idle":"2022-11-15T18:33:45.394193Z","shell.execute_reply.started":"2022-11-15T18:33:45.344494Z","shell.execute_reply":"2022-11-15T18:33:45.392846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for column in data.columns:\n    data[column] = (data[column] - data[column].min()) / (data[column].max() - data[column].min()) \ndata.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:34:04.965848Z","iopub.execute_input":"2022-11-15T18:34:04.966358Z","iopub.status.idle":"2022-11-15T18:34:05.00211Z","shell.execute_reply.started":"2022-11-15T18:34:04.966313Z","shell.execute_reply":"2022-11-15T18:34:05.000546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:34:32.97953Z","iopub.execute_input":"2022-11-15T18:34:32.980025Z","iopub.status.idle":"2022-11-15T18:34:32.991523Z","shell.execute_reply.started":"2022-11-15T18:34:32.979966Z","shell.execute_reply":"2022-11-15T18:34:32.990323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=data.drop(['id'],axis=1)\ndata.info()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:34:49.118082Z","iopub.execute_input":"2022-11-15T18:34:49.118479Z","iopub.status.idle":"2022-11-15T18:34:49.134967Z","shell.execute_reply.started":"2022-11-15T18:34:49.118448Z","shell.execute_reply":"2022-11-15T18:34:49.133813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['diagnosis_result'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:35:05.403226Z","iopub.execute_input":"2022-11-15T18:35:05.403653Z","iopub.status.idle":"2022-11-15T18:35:05.415116Z","shell.execute_reply.started":"2022-11-15T18:35:05.4036Z","shell.execute_reply":"2022-11-15T18:35:05.413713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cls_0=data[data['diagnosis_result']==0]\ncls_1=data[data['diagnosis_result']==1]","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:35:19.461693Z","iopub.execute_input":"2022-11-15T18:35:19.46213Z","iopub.status.idle":"2022-11-15T18:35:19.46913Z","shell.execute_reply.started":"2022-11-15T18:35:19.462096Z","shell.execute_reply":"2022-11-15T18:35:19.468155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_class_1_over = cls_1.sample(250, replace=True)\ndf_class_0_over = cls_0.sample(250, replace=True)\ndf_test_over = pd.concat([df_class_0_over, df_class_1_over], axis=0)\ndf_test_over.info()","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:35:37.857698Z","iopub.execute_input":"2022-11-15T18:35:37.858091Z","iopub.status.idle":"2022-11-15T18:35:37.876451Z","shell.execute_reply.started":"2022-11-15T18:35:37.858058Z","shell.execute_reply":"2022-11-15T18:35:37.874745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y1=df_test_over['diagnosis_result']\ndf_test_over=df_test_over.drop(['diagnosis_result'],axis=1)\nX1=df_test_over","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:35:57.160646Z","iopub.execute_input":"2022-11-15T18:35:57.161065Z","iopub.status.idle":"2022-11-15T18:35:57.169075Z","shell.execute_reply.started":"2022-11-15T18:35:57.161034Z","shell.execute_reply":"2022-11-15T18:35:57.167221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nX1_s_train,X1_s_test ,y1_s_train, y1_s_test = train_test_split(X1,y1,\n                                                   test_size=0.25,\n                                                   random_state=0,\n                                                  shuffle = True,\n                                                  stratify = y1)\n\nprint('training data shape is :{}.'.format(X1_s_train.shape))\nprint('training label shape is :{}.'.format(y1_s_train.shape))\nprint('testing data shape is :{}.'.format(X1_s_test.shape))\nprint('testing label shape is :{}.'.format(y1_s_test.shape))","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:36:15.947311Z","iopub.execute_input":"2022-11-15T18:36:15.947767Z","iopub.status.idle":"2022-11-15T18:36:16.022241Z","shell.execute_reply.started":"2022-11-15T18:36:15.947725Z","shell.execute_reply":"2022-11-15T18:36:16.020837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.svm import SVC\nsvc_s_model = SVC(kernel='poly',gamma=8)\nsvc_s_model.fit(X1_s_train, y1_s_train)","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:36:31.767399Z","iopub.execute_input":"2022-11-15T18:36:31.767814Z","iopub.status.idle":"2022-11-15T18:36:31.907606Z","shell.execute_reply.started":"2022-11-15T18:36:31.76778Z","shell.execute_reply":"2022-11-15T18:36:31.906411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from xgboost import XGBClassifier\nxgb=XGBClassifier()\nxgb.fit(X1_s_train,y1_s_train)","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:36:50.721262Z","iopub.execute_input":"2022-11-15T18:36:50.721687Z","iopub.status.idle":"2022-11-15T18:36:51.124593Z","shell.execute_reply.started":"2022-11-15T18:36:50.721649Z","shell.execute_reply":"2022-11-15T18:36:51.123708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, confusion_matrix, classification_report\npredictions= svc_s_model.predict(X1_s_train)\npercentage=svc_s_model.score(X1_s_train,y1_s_train)\nres=confusion_matrix(y1_s_train,predictions)\nprint(\"Training confusion matrix\")\nprint(res)\npredictions= svc_s_model.predict(X1_s_test)\npercentage=svc_s_model.score(X1_s_test,y1_s_test)\nres=confusion_matrix(y1_s_test,predictions)\nprint(\"validation confusion matrix\")\nprint(res)\nprint(classification_report(y1_s_test, predictions))\n# check the accuracy on the training set\nprint('training accuracy = '+str(svc_s_model.score(X1_s_train, y1_s_train)*100))\nprint('testing accuracy = '+str(svc_s_model.score(X1_s_test, y1_s_test)*100))","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:37:12.926384Z","iopub.execute_input":"2022-11-15T18:37:12.927544Z","iopub.status.idle":"2022-11-15T18:37:12.966884Z","shell.execute_reply.started":"2022-11-15T18:37:12.927499Z","shell.execute_reply":"2022-11-15T18:37:12.965948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, confusion_matrix, classification_report\npredictions= xgb.predict(X1_s_train)\npercentage=xgb.score(X1_s_train,y1_s_train)\nres=confusion_matrix(y1_s_train,predictions)\nprint(\"Training confusion matrix\")\nprint(res)\npredictions= xgb.predict(X1_s_test)\npercentage=xgb.score(X1_s_test,y1_s_test)\nres=confusion_matrix(y1_s_test,predictions)\nprint(\"validation confusion matrix\")\nprint(res)\nprint(classification_report(y1_s_test, predictions))\n# check the accuracy on the training set\nprint('training accuracy = '+str(xgb.score(X1_s_train, y1_s_train)*100))\nprint('testing accuracy = '+str(xgb.score(X1_s_test, y1_s_test)*100))","metadata":{"execution":{"iopub.status.busy":"2022-11-15T18:37:43.661482Z","iopub.execute_input":"2022-11-15T18:37:43.662694Z","iopub.status.idle":"2022-11-15T18:37:43.711609Z","shell.execute_reply.started":"2022-11-15T18:37:43.662647Z","shell.execute_reply":"2022-11-15T18:37:43.710684Z"},"trusted":true},"execution_count":null,"outputs":[]}]}