{"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 matplotlib.image as pltimg\nfrom PIL import Image\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":"2021-07-28T01:55:26.207641Z","iopub.execute_input":"2021-07-28T01:55:26.208319Z","iopub.status.idle":"2021-07-28T01:55:26.224942Z","shell.execute_reply.started":"2021-07-28T01:55:26.208227Z","shell.execute_reply":"2021-07-28T01:55:26.223762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# unzip samples files\n\n!unzip -oq /kaggle/input/diabetic-retinopathy-detection/sample.zip\n!unzip -oq /kaggle/input/diabetic-retinopathy-detection/trainLabels.csv.zip\n\n\ntrainCSVFile = 'trainLabels.csv'\ndf = pd.read_csv(trainCSVFile)\ndf = df.astype({'image': str})\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-28T01:55:26.226445Z","iopub.execute_input":"2021-07-28T01:55:26.226757Z","iopub.status.idle":"2021-07-28T01:55:28.315586Z","shell.execute_reply.started":"2021-07-28T01:55:26.226725Z","shell.execute_reply":"2021-07-28T01:55:28.314596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2021-07-28T01:55:28.317244Z","iopub.execute_input":"2021-07-28T01:55:28.31755Z","iopub.status.idle":"2021-07-28T01:55:28.343164Z","shell.execute_reply.started":"2021-07-28T01:55:28.317522Z","shell.execute_reply":"2021-07-28T01:55:28.341626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"counts = df['level'].value_counts().sort_index()\ncounts","metadata":{"execution":{"iopub.status.busy":"2021-07-28T01:55:28.344884Z","iopub.execute_input":"2021-07-28T01:55:28.345181Z","iopub.status.idle":"2021-07-28T01:55:28.369238Z","shell.execute_reply.started":"2021-07-28T01:55:28.345152Z","shell.execute_reply":"2021-07-28T01:55:28.368008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"graph = plt.barh(counts.index, counts.values)\ntitle = plt.title('Number for each disease')\nxlabel = plt.xlabel('Number')\nylabel = plt.ylabel('Grade')","metadata":{"execution":{"iopub.status.busy":"2021-07-28T01:55:28.370909Z","iopub.execute_input":"2021-07-28T01:55:28.371461Z","iopub.status.idle":"2021-07-28T01:55:28.568465Z","shell.execute_reply.started":"2021-07-28T01:55:28.371398Z","shell.execute_reply":"2021-07-28T01:55:28.567164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_images = [_.replace('.jpeg', '') for _ in os.listdir('sample')]\n\ndf = df[df['image'].isin(sample_images)]\ndf","metadata":{"execution":{"iopub.status.busy":"2021-07-28T01:55:28.570082Z","iopub.execute_input":"2021-07-28T01:55:28.570583Z","iopub.status.idle":"2021-07-28T01:55:28.590105Z","shell.execute_reply.started":"2021-07-28T01:55:28.570535Z","shell.execute_reply":"2021-07-28T01:55:28.588855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"def open_image(img: str) -> None:\n    \"\"\"\n    View images, multiple of them and prints the image name and severity\n    \n    Args:\n        img: str - path to image files\n    \"\"\"\n    name = img.replace('.jpeg', '')\n    title = str(df[df['image']==name])\n    file = 'sample/' + img \n    fig = plt.figure()\n    plt.title(title)\n    img_read = plt.imread(file)\n    img_show = plt.imshow(img_read)\n\n    ax = plt.axis('off')\n    \nfor img in os.listdir('sample'):\n    open_image(img)","metadata":{"execution":{"iopub.status.busy":"2021-07-28T01:55:28.593218Z","iopub.execute_input":"2021-07-28T01:55:28.593704Z","iopub.status.idle":"2021-07-28T01:55:46.73823Z","shell.execute_reply.started":"2021-07-28T01:55:28.593657Z","shell.execute_reply":"2021-07-28T01:55:46.737274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}