{"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":"**# Steps\n\n1. reading CSV file\n","metadata":{}},{"cell_type":"code","source":"%matplotlib inline\nimport math\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport os\n\nfrom skimage import measure\nfrom skimage.color import rgb2gray\nfrom skimage.util import img_as_ubyte\nfrom skimage import io\nfrom skimage.feature import greycomatrix, greycoprops","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:13:11.145717Z","iopub.execute_input":"2023-04-26T18:13:11.146684Z","iopub.status.idle":"2023-04-26T18:13:14.115653Z","shell.execute_reply.started":"2023-04-26T18:13:11.146561Z","shell.execute_reply":"2023-04-26T18:13:14.114629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Mild Class**","metadata":{}},{"cell_type":"code","source":"imgList = os.listdir('/kaggle/input/mildclass/')\n","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:13:14.118756Z","iopub.execute_input":"2023-04-26T18:13:14.119046Z","iopub.status.idle":"2023-04-26T18:13:14.141170Z","shell.execute_reply.started":"2023-04-26T18:13:14.119018Z","shell.execute_reply":"2023-04-26T18:13:14.140323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imgPath = []\nfor path in imgList:\n    pathImg = f'/kaggle/input/mildclass/{path}'\n    imgPath.append(pathImg)\nimgPath.sort()\n","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:13:14.142493Z","iopub.execute_input":"2023-04-26T18:13:14.143148Z","iopub.status.idle":"2023-04-26T18:13:14.147818Z","shell.execute_reply.started":"2023-04-26T18:13:14.143111Z","shell.execute_reply":"2023-04-26T18:13:14.146979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = []\nay = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[0], levels=256)\n    ax.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    ay.append(greycoprops(glcm, 'correlation')[0, 0])","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:13:14.149491Z","iopub.execute_input":"2023-04-26T18:13:14.150138Z","iopub.status.idle":"2023-04-26T18:13:26.565764Z","shell.execute_reply.started":"2023-04-26T18:13:14.150100Z","shell.execute_reply":"2023-04-26T18:13:26.564901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nbx = []\nby = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[0.785398], levels=256)\n    bx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    by.append(greycoprops(glcm, 'correlation')[0, 0])","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:13:26.569560Z","iopub.execute_input":"2023-04-26T18:13:26.569948Z","iopub.status.idle":"2023-04-26T18:13:37.529532Z","shell.execute_reply.started":"2023-04-26T18:13:26.569908Z","shell.execute_reply":"2023-04-26T18:13:37.528538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cx = []\ncy = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[1.0472], levels=256)\n    cx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    cy.append(greycoprops(glcm, 'correlation')[0, 0])","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:13:37.532209Z","iopub.execute_input":"2023-04-26T18:13:37.532476Z","iopub.status.idle":"2023-04-26T18:13:48.757193Z","shell.execute_reply.started":"2023-04-26T18:13:37.532449Z","shell.execute_reply":"2023-04-26T18:13:48.756104Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dx = []\ndy = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[2.0944], levels=256)\n    dx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    dy.append(greycoprops(glcm, 'correlation')[0, 0])","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:13:48.758836Z","iopub.execute_input":"2023-04-26T18:13:48.759212Z","iopub.status.idle":"2023-04-26T18:13:59.520190Z","shell.execute_reply.started":"2023-04-26T18:13:48.759174Z","shell.execute_reply":"2023-04-26T18:13:59.519288Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ex = []\ney = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[3.14159], levels=256)\n    ex.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    ey.append(greycoprops(glcm, 'correlation')[0, 0])","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:13:59.521493Z","iopub.execute_input":"2023-04-26T18:13:59.521930Z","iopub.status.idle":"2023-04-26T18:14:10.284214Z","shell.execute_reply.started":"2023-04-26T18:13:59.521869Z","shell.execute_reply":"2023-04-26T18:14:10.283327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fx = []\nfy = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[4.18879], levels=256)\n    fx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    fy.append(greycoprops(glcm, 'correlation')[0, 0])","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:14:10.285483Z","iopub.execute_input":"2023-04-26T18:14:10.285867Z","iopub.status.idle":"2023-04-26T18:14:21.806989Z","shell.execute_reply.started":"2023-04-26T18:14:10.285833Z","shell.execute_reply":"2023-04-26T18:14:21.806090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-04-26T18:14:21.808642Z","iopub.execute_input":"2023-04-26T18:14:21.809047Z","iopub.status.idle":"2023-04-26T18:14:21.814027Z","shell.execute_reply.started":"2023-04-26T18:14:21.809006Z","shell.execute_reply":"2023-04-26T18:14:21.812989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imgName = os.listdir('/kaggle/input/mildclass/')\nimgName.sort()","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:14:21.815423Z","iopub.execute_input":"2023-04-26T18:14:21.816032Z","iopub.status.idle":"2023-04-26T18:14:21.829756Z","shell.execute_reply.started":"2023-04-26T18:14:21.815990Z","shell.execute_reply":"2023-04-26T18:14:21.828623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.DataFrame(dict(image_name=imgName, ax=ax, ay=ay, bx=bx, by=by, cx=cx, cy=cy, dx=dx, dy=dy, ex=ex, ey=ey, fx=fx, fy=fy,label=1))\nsubmission = submission.sort_values('image_name') \nsubmission.to_csv('submission.csv', index=False)\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:14:21.831410Z","iopub.execute_input":"2023-04-26T18:14:21.831814Z","iopub.status.idle":"2023-04-26T18:14:22.375091Z","shell.execute_reply.started":"2023-04-26T18:14:21.831770Z","shell.execute_reply":"2023-04-26T18:14:22.373912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Moderate Class**","metadata":{}},{"cell_type":"code","source":"imgList = os.listdir('/kaggle/input/moderateclass/')\n","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:14:22.376484Z","iopub.execute_input":"2023-04-26T18:14:22.376873Z","iopub.status.idle":"2023-04-26T18:14:22.392893Z","shell.execute_reply.started":"2023-04-26T18:14:22.376833Z","shell.execute_reply":"2023-04-26T18:14:22.392197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imgPath = []\nfor path in imgList:\n    pathImg = f'/kaggle/input/moderateclass/{path}'\n    imgPath.append(pathImg)\nimgPath.sort()\n","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:14:22.395838Z","iopub.execute_input":"2023-04-26T18:14:22.396105Z","iopub.status.idle":"2023-04-26T18:14:22.400727Z","shell.execute_reply.started":"2023-04-26T18:14:22.396079Z","shell.execute_reply":"2023-04-26T18:14:22.399912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = []\nay = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[0], levels=256)\n    ax.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    ay.append(greycoprops(glcm, 'correlation')[0, 0])\n    \n\nbx = []\nby = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[0.785398], levels=256)\n    bx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    by.append(greycoprops(glcm, 'correlation')[0, 0])\n    \ncx = []\ncy = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[1.0472], levels=256)\n    cx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    cy.append(greycoprops(glcm, 'correlation')[0, 0])\n\ndx = []\ndy = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[2.0944], levels=256)\n    dx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    dy.append(greycoprops(glcm, 'correlation')[0, 0])\n    \nex = []\ney = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[3.14159], levels=256)\n    ex.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    ey.append(greycoprops(glcm, 'correlation')[0, 0])\n    \nfx = []\nfy = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[4.18879], levels=256)\n    fx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    fy.append(greycoprops(glcm, 'correlation')[0, 0])","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:14:22.402078Z","iopub.execute_input":"2023-04-26T18:14:22.402584Z","iopub.status.idle":"2023-04-26T18:15:20.760967Z","shell.execute_reply.started":"2023-04-26T18:14:22.402545Z","shell.execute_reply":"2023-04-26T18:15:20.759831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imgName = os.listdir('/kaggle/input/moderateclass')\nimgName.sort()","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:15:20.762445Z","iopub.execute_input":"2023-04-26T18:15:20.762810Z","iopub.status.idle":"2023-04-26T18:15:20.769908Z","shell.execute_reply.started":"2023-04-26T18:15:20.762772Z","shell.execute_reply":"2023-04-26T18:15:20.768998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission2 = pd.DataFrame(dict(image_name=imgName, ax=ax, ay=ay, bx=bx, by=by, cx=cx, cy=cy, dx=dx, dy=dy, ex=ex, ey=ey, fx=fx, fy=fy,label=2))\nsubmission2 = submission2.sort_values('image_name') \nsubmission2.to_csv('submission2.csv', index=False)\nsubmission2.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:15:20.771517Z","iopub.execute_input":"2023-04-26T18:15:20.771897Z","iopub.status.idle":"2023-04-26T18:15:20.802873Z","shell.execute_reply.started":"2023-04-26T18:15:20.771842Z","shell.execute_reply":"2023-04-26T18:15:20.801078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**No DR Class**","metadata":{}},{"cell_type":"code","source":"imgList = os.listdir('/kaggle/input/nodrclass/')\nimgPath = []\nfor path in imgList:\n    pathImg = f'/kaggle/input/nodrclass/{path}'\n    imgPath.append(pathImg)\nimgPath.sort()\n","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:15:20.803901Z","iopub.execute_input":"2023-04-26T18:15:20.804152Z","iopub.status.idle":"2023-04-26T18:15:20.820169Z","shell.execute_reply.started":"2023-04-26T18:15:20.804127Z","shell.execute_reply":"2023-04-26T18:15:20.819348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = []\nay = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[0], levels=256)\n    ax.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    ay.append(greycoprops(glcm, 'correlation')[0, 0])\n    \n\nbx = []\nby = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[0.785398], levels=256)\n    bx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    by.append(greycoprops(glcm, 'correlation')[0, 0])\n    \ncx = []\ncy = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[1.0472], levels=256)\n    cx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    cy.append(greycoprops(glcm, 'correlation')[0, 0])\n\ndx = []\ndy = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[2.0944], levels=256)\n    dx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    dy.append(greycoprops(glcm, 'correlation')[0, 0])\n    \nex = []\ney = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[3.14159], levels=256)\n    ex.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    ey.append(greycoprops(glcm, 'correlation')[0, 0])\n    \nfx = []\nfy = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[4.18879], levels=256)\n    fx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    fy.append(greycoprops(glcm, 'correlation')[0, 0])","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:15:20.823259Z","iopub.execute_input":"2023-04-26T18:15:20.823537Z","iopub.status.idle":"2023-04-26T18:16:44.408515Z","shell.execute_reply.started":"2023-04-26T18:15:20.823507Z","shell.execute_reply":"2023-04-26T18:16:44.407414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imgName = os.listdir('/kaggle/input/nodrclass')\nimgName.sort()","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:16:44.409992Z","iopub.execute_input":"2023-04-26T18:16:44.410353Z","iopub.status.idle":"2023-04-26T18:16:44.415868Z","shell.execute_reply.started":"2023-04-26T18:16:44.410317Z","shell.execute_reply":"2023-04-26T18:16:44.414984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission3 = pd.DataFrame(dict(image_name=imgName, ax=ax, ay=ay, bx=bx, by=by, cx=cx, cy=cy, dx=dx, dy=dy, ex=ex, ey=ey, fx=fx, fy=fy,label=3))\nsubmission3 = submission3.sort_values('image_name') \nsubmission3.to_csv('submission3.csv', index=False)\nsubmission3.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:16:44.417295Z","iopub.execute_input":"2023-04-26T18:16:44.417924Z","iopub.status.idle":"2023-04-26T18:16:44.450545Z","shell.execute_reply.started":"2023-04-26T18:16:44.417884Z","shell.execute_reply":"2023-04-26T18:16:44.449605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**DR CLASS**","metadata":{}},{"cell_type":"code","source":"imgList = os.listdir('/kaggle/input/drclass/')\nimgPath = []\nfor path in imgList:\n    pathImg = f'/kaggle/input/drclass/{path}'\n    imgPath.append(pathImg)\nimgPath.sort()\n","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:16:44.453591Z","iopub.execute_input":"2023-04-26T18:16:44.453867Z","iopub.status.idle":"2023-04-26T18:16:44.475574Z","shell.execute_reply.started":"2023-04-26T18:16:44.453841Z","shell.execute_reply":"2023-04-26T18:16:44.474953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = []\nay = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[0], levels=256)\n    ax.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    ay.append(greycoprops(glcm, 'correlation')[0, 0])\n    \n\nbx = []\nby = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[0.785398], levels=256)\n    bx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    by.append(greycoprops(glcm, 'correlation')[0, 0])\n    \ncx = []\ncy = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[1.0472], levels=256)\n    cx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    cy.append(greycoprops(glcm, 'correlation')[0, 0])\n\ndx = []\ndy = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[2.0944], levels=256)\n    dx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    dy.append(greycoprops(glcm, 'correlation')[0, 0])\n    \nex = []\ney = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[3.14159], levels=256)\n    ex.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    ey.append(greycoprops(glcm, 'correlation')[0, 0])\n    \nfx = []\nfy = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[4.18879], levels=256)\n    fx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    fy.append(greycoprops(glcm, 'correlation')[0, 0])","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:16:44.476656Z","iopub.execute_input":"2023-04-26T18:16:44.476981Z","iopub.status.idle":"2023-04-26T18:18:40.960701Z","shell.execute_reply.started":"2023-04-26T18:16:44.476950Z","shell.execute_reply":"2023-04-26T18:18:40.959829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imgName = os.listdir('/kaggle/input/drclass')\nimgName.sort()","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:18:40.962347Z","iopub.execute_input":"2023-04-26T18:18:40.962720Z","iopub.status.idle":"2023-04-26T18:18:40.969071Z","shell.execute_reply.started":"2023-04-26T18:18:40.962675Z","shell.execute_reply":"2023-04-26T18:18:40.967934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission4 = pd.DataFrame(dict(image_name=imgName, ax=ax, ay=ay, bx=bx, by=by, cx=cx, cy=cy, dx=dx, dy=dy, ex=ex, ey=ey, fx=fx, fy=fy,label=4))\nsubmission4 = submission4.sort_values('image_name') \nsubmission4.to_csv('submission4.csv', index=False)\nsubmission4.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:18:40.972637Z","iopub.execute_input":"2023-04-26T18:18:40.972989Z","iopub.status.idle":"2023-04-26T18:18:41.005788Z","shell.execute_reply.started":"2023-04-26T18:18:40.972942Z","shell.execute_reply":"2023-04-26T18:18:41.004829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Severe Class**","metadata":{}},{"cell_type":"code","source":"imgList = os.listdir('/kaggle/input/severeclass/')\nimgPath = []\nfor path in imgList:\n    pathImg = f'/kaggle/input/severeclass/{path}'\n    imgPath.append(pathImg)\nimgPath.sort()\n","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:19:06.834534Z","iopub.execute_input":"2023-04-26T18:19:06.834948Z","iopub.status.idle":"2023-04-26T18:19:06.842015Z","shell.execute_reply.started":"2023-04-26T18:19:06.834909Z","shell.execute_reply":"2023-04-26T18:19:06.840896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = []\nay = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[0], levels=256)\n    ax.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    ay.append(greycoprops(glcm, 'correlation')[0, 0])\n    \n\nbx = []\nby = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[0.785398], levels=256)\n    bx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    by.append(greycoprops(glcm, 'correlation')[0, 0])\n    \ncx = []\ncy = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[1.0472], levels=256)\n    cx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    cy.append(greycoprops(glcm, 'correlation')[0, 0])\n\ndx = []\ndy = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[2.0944], levels=256)\n    dx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    dy.append(greycoprops(glcm, 'correlation')[0, 0])\n    \nex = []\ney = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[3.14159], levels=256)\n    ex.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    ey.append(greycoprops(glcm, 'correlation')[0, 0])\n    \nfx = []\nfy = []\nfor patch in imgPath:\n    image_rgb = io.imread(patch)\n    image = img_as_ubyte(rgb2gray(image_rgb))\n    glcm = greycomatrix(image, distances=[4], angles=[4.18879], levels=256)\n    fx.append(greycoprops(glcm, 'dissimilarity')[0, 0])\n    fy.append(greycoprops(glcm, 'correlation')[0, 0])","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:19:08.062342Z","iopub.execute_input":"2023-04-26T18:19:08.062685Z","iopub.status.idle":"2023-04-26T18:21:28.690344Z","shell.execute_reply.started":"2023-04-26T18:19:08.062652Z","shell.execute_reply":"2023-04-26T18:21:28.689168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imgName = os.listdir('/kaggle/input/severeclass')\nimgName.sort()","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:22:53.053378Z","iopub.execute_input":"2023-04-26T18:22:53.053742Z","iopub.status.idle":"2023-04-26T18:22:53.059666Z","shell.execute_reply.started":"2023-04-26T18:22:53.053709Z","shell.execute_reply":"2023-04-26T18:22:53.058848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission5 = pd.DataFrame(dict(image_name=imgName, ax=ax, ay=ay, bx=bx, by=by, cx=cx, cy=cy, dx=dx, dy=dy, ex=ex, ey=ey, fx=fx, fy=fy,label=5))\nsubmission5 = submission5.sort_values('image_name') \nsubmission5.to_csv('submission5.csv', index=False)\nsubmission5.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:24:55.577631Z","iopub.execute_input":"2023-04-26T18:24:55.577998Z","iopub.status.idle":"2023-04-26T18:24:55.607488Z","shell.execute_reply.started":"2023-04-26T18:24:55.577966Z","shell.execute_reply":"2023-04-26T18:24:55.606614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"frames = [submission, submission2, submission3, submission4, submission5]\n\nresult = pd.concat(frames)","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:23:35.162482Z","iopub.execute_input":"2023-04-26T18:23:35.162901Z","iopub.status.idle":"2023-04-26T18:23:35.170847Z","shell.execute_reply.started":"2023-04-26T18:23:35.162850Z","shell.execute_reply":"2023-04-26T18:23:35.169602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result = result.sort_values('image_name') \nresult.to_csv('result.csv', index=False)\nresult.head","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:27:09.463607Z","iopub.execute_input":"2023-04-26T18:27:09.463950Z","iopub.status.idle":"2023-04-26T18:27:09.490307Z","shell.execute_reply.started":"2023-04-26T18:27:09.463917Z","shell.execute_reply":"2023-04-26T18:27:09.489356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result.label.count","metadata":{"execution":{"iopub.status.busy":"2023-04-26T18:26:20.313815Z","iopub.execute_input":"2023-04-26T18:26:20.314182Z","iopub.status.idle":"2023-04-26T18:26:20.320720Z","shell.execute_reply.started":"2023-04-26T18:26:20.314151Z","shell.execute_reply":"2023-04-26T18:26:20.319799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Classifiers**\nsvm\nrandom forest\nperceptron\nknn\nnaive bayes\nlogistic regression","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"**KNN**","metadata":{}},{"cell_type":"code","source":"# K-Nearest Neighbors (K-NN)\n\n# Importing the libraries\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd\n\n# Importing the dataset\ndataset = pd.read_csv('result.csv')\nX = dataset.iloc[:, 1:13].values\ny = dataset.iloc[:, 13].values\n\n","metadata":{"execution":{"iopub.status.busy":"2023-04-26T19:07:25.233052Z","iopub.execute_input":"2023-04-26T19:07:25.233432Z","iopub.status.idle":"2023-04-26T19:07:25.244415Z","shell.execute_reply.started":"2023-04-26T19:07:25.233403Z","shell.execute_reply":"2023-04-26T19:07:25.243679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Splitting the dataset into the Training set and Test set\nfrom sklearn.model_selection import train_test_split\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)\n\n# Feature Scaling\nfrom sklearn.preprocessing import StandardScaler\nsc = StandardScaler()\nX_train = sc.fit_transform(X_train)\nX_test = sc.transform(X_test)\n\n","metadata":{"execution":{"iopub.status.busy":"2023-04-26T19:07:46.564407Z","iopub.execute_input":"2023-04-26T19:07:46.564776Z","iopub.status.idle":"2023-04-26T19:07:46.975642Z","shell.execute_reply.started":"2023-04-26T19:07:46.564741Z","shell.execute_reply":"2023-04-26T19:07:46.974497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Fitting K-NN to the Training set\nfrom sklearn.neighbors import KNeighborsClassifier\nclassifier = KNeighborsClassifier(n_neighbors = 3, metric = 'minkowski')\nclassifier.fit(X_train, y_train)\n\n","metadata":{"execution":{"iopub.status.busy":"2023-04-26T19:17:18.838971Z","iopub.execute_input":"2023-04-26T19:17:18.839306Z","iopub.status.idle":"2023-04-26T19:17:18.849479Z","shell.execute_reply.started":"2023-04-26T19:17:18.839278Z","shell.execute_reply":"2023-04-26T19:17:18.848569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Predicting the Test set results\ny_pred = classifier.predict(X_test)\n\n# Making the Confusion Matrix\nfrom sklearn.metrics import confusion_matrix\ncm = confusion_matrix(y_test, y_pred)","metadata":{"execution":{"iopub.status.busy":"2023-04-26T19:17:19.309492Z","iopub.execute_input":"2023-04-26T19:17:19.309825Z","iopub.status.idle":"2023-04-26T19:17:19.322817Z","shell.execute_reply.started":"2023-04-26T19:17:19.309794Z","shell.execute_reply":"2023-04-26T19:17:19.321762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cm","metadata":{"execution":{"iopub.status.busy":"2023-04-26T19:17:19.784511Z","iopub.execute_input":"2023-04-26T19:17:19.784874Z","iopub.status.idle":"2023-04-26T19:17:19.794205Z","shell.execute_reply.started":"2023-04-26T19:17:19.784829Z","shell.execute_reply":"2023-04-26T19:17:19.792986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\n\nacc = accuracy_score(y_test, y_pred)\nacc","metadata":{"execution":{"iopub.status.busy":"2023-04-26T19:17:20.215323Z","iopub.execute_input":"2023-04-26T19:17:20.215674Z","iopub.status.idle":"2023-04-26T19:17:20.222709Z","shell.execute_reply.started":"2023-04-26T19:17:20.215643Z","shell.execute_reply":"2023-04-26T19:17:20.221818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}