{"cells":[{"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":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport PIL.Image as Image, PIL.ImageDraw as ImageDraw, PIL.ImageFont as ImageFont\nimport plotly.graph_objects as go\nfrom scipy.stats import norm","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Thanks to Peter for a great notebook on EDA  - Check it out here:\n\nhttps://www.kaggle.com/pestipeti/bengali-quick-eda"},{"metadata":{"trusted":true},"cell_type":"code","source":"HEIGHT = 137\nWIDTH = 236","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def load_as_npa(file):\n    df = pd.read_parquet(file)\n    return df.iloc[:, 1:].values.reshape(-1 , HEIGHT , WIDTH)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def image_from_char(char):\n    image = Image.new('RGB', (WIDTH, HEIGHT))\n    draw = ImageDraw.Draw(image)\n    myfont = ImageFont.truetype('/kaggle/input/bengalifont/HindSiliguri.ttf', 120)\n    w, h = draw.textsize(char, font=myfont)\n    draw.text(((WIDTH - w) / 2,(HEIGHT - h) / 2), char, font=myfont)\n\n    return image","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%%time\nimages0 = load_as_npa('/kaggle/input/bengaliai-cv19/train_image_data_0.parquet')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig , ax = plt.subplots(5,5,figsize = (15,10))\nax = ax.flatten()\n\nfor i in range(25):\n    ax[i].imshow(images0[i], cmap='Greys')\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train = pd.read_csv('/kaggle/input/bengaliai-cv19/train.csv')\ndf_train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_classmap = pd.read_csv('/kaggle/input/bengaliai-cv19/class_map.csv')\ndf_classmap.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_classmap.shape","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"1. Grapheme Roots-"},{"metadata":{"trusted":true},"cell_type":"code","source":"print(\"Unique grapheme roots:\" ,df_train['grapheme_root'].nunique())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.set(rc={'figure.figsize':(10,10)})","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Histogram with maximum likelihood gaussian distribution fit :"},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.distplot(df_train['grapheme_root'] ,fit=norm , kde=False)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Histogram with frequencies  -"},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.distplot(df_train['grapheme_root'] ,kde=False)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"KDE function -"},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.kdeplot(df_train['grapheme_root'] , shade=True)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"2. Vowel Diacritics :"},{"metadata":{"trusted":true},"cell_type":"code","source":"print(\"Unique vowel diacritcs : \",df_train['vowel_diacritic'].nunique())","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Histogram with frequencies :"},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.distplot(df_train['vowel_diacritic'] , kde=False )","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"KDE function :"},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.kdeplot(df_train['vowel_diacritic'] , shade=True)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Take a look at the vowel diacritics -"},{"metadata":{"trusted":true},"cell_type":"code","source":"x = df_train['vowel_diacritic'].value_counts().sort_values().index\nvowels = df_classmap[(df_classmap['component_type'] == 'vowel_diacritic') & (df_classmap['label'].isin(x))]['component']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(3, 5, figsize=(15, 10))\nax = ax.flatten()\n\nfor i in range(15):\n    if i < len(vowels):\n        ax[i].imshow(image_from_char(vowels.values[i]), cmap='Greys' )\n        ax[i].grid(None)\n        ","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"3. Consonant Diacritics "},{"metadata":{"trusted":true},"cell_type":"code","source":"print(\"Unique consonant diacritcs : \",df_train['consonant_diacritic'].nunique())","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Histogram with frequencies :"},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.distplot(df_train['consonant_diacritic'] , kde=False )","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"KDE function :"},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.kdeplot(df_train['consonant_diacritic'] , shade=True )","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Take a look at the consonant diacritics :"},{"metadata":{"trusted":true},"cell_type":"code","source":"y = df_train['consonant_diacritic'].value_counts().sort_values().index\nconsonants = df_classmap[(df_classmap['component_type'] == 'consonant_diacritic') & (df_classmap['label'].isin(y))]['component']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(2, 5, figsize=(16, 10))\nax = ax.flatten()\n\n\nfor i in range(15):\n    if i < len(consonants):\n        ax[i].imshow(image_from_char(consonants.values[i]), cmap='Greys' )\n        ax[i].grid(None)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":""},{"metadata":{"trusted":true},"cell_type":"code","source":"df_submission = pd.read_csv('/kaggle/input/bengaliai-cv19/sample_submission.csv')\ndf_submission['target'] = 0\ndf_submission.to_csv(\"submission.csv\", index=False)","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":4}