{"cells":[{"metadata":{},"cell_type":"markdown","source":"#### Simple script to start to explore graphene roots by group.\n\nAs someone with no previous exposure to Bengali, I wasted to do some quick visual EDA by graphene root so start to get an idea how similar images in a graphene root might be.\n\n"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"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 in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the \"../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# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import pyarrow.parquet as pq\nimport matplotlib.pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"HEIGHT = 137\nWIDTH = 236\ndf = pd.read_parquet('/kaggle/input/bengaliai-cv19/train_image_data_0.parquet')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_labels = pd.read_csv('/kaggle/input/bengaliai-cv19/train.csv')\ntrain_labels.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"What are some of the graphene roots with the most images?"},{"metadata":{"trusted":true},"cell_type":"code","source":"# most represented in train data\ntrain_labels.groupby('grapheme_root').agg('count').reset_index()[['grapheme_root','grapheme']].sort_values('grapheme', ascending=False).head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# least represented in train data\ntrain_labels.groupby('grapheme_root').agg('count').reset_index()[['grapheme_root','grapheme']].sort_values('grapheme').head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"## We can now filter a small df with the graphene we want to further explore (lets try graphene = 72)\nfiltered_df = train_labels[train_labels['grapheme_root'] == 72]\nimg_ids =  filtered_df['image_id'].values\nprint(\"There are {} images in train0 of grapehene root = 72\".format(len(filtered_df)))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"## filter the images to the ones of interest:\nfiltered_imgs = df[df['image_id'].isin(img_ids)]\n#check how many we have in our subset of images (train0)\nprint(\"Number of images in train0 with graphene root = 72: {}\".format(len(filtered_imgs)))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"images_72 = filtered_imgs.iloc[:, 1:].values.reshape(-1, HEIGHT, WIDTH)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"f, ax = plt.subplots(4, 4, figsize=(16, 8))\nax = ax.flatten()\nfor i in range(16):\n    ax[i].imshow(images_72[i], cmap='Greys')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"## We can now filter a small df with the graphene we want to further explore (lets try graphene = 73)\nfiltered_df = train_labels[train_labels['grapheme_root'] == 73]\nimg_ids =  filtered_df['image_id'].values\nprint(\"There are {} images in train0 of grapehene root = 73\".format(len(filtered_df)))\n######\n## filter the images to the ones of interest:\nfiltered_imgs = df[df['image_id'].isin(img_ids)]\n#check how many we have in our subset of images (train0)\nprint(\"Number of images in train0 with graphene root = 73: {}\".format(len(filtered_imgs)))\nimages_73 = filtered_imgs.iloc[:, 1:].values.reshape(-1, HEIGHT, WIDTH)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"f, ax = plt.subplots(4, 4, figsize=(16, 8))\nax = ax.flatten()\nfor i in range(16):\n    ax[i].imshow(images_73[i], cmap='Greys')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":1}