{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Kaggle Korea 3rd Competition \n대회를 열어주신 태진님 외 관계자분들 감사합니다."},{"metadata":{},"cell_type":"markdown","source":"### 필요한 Module들을 Import 해줍니다.\n\n제가 생각하는 모듈들의 역할들입니다.\n\n- numpy : 행렬 및 백터연산에 특화되어있는 모듈입니다.\n- pandas : table 형태의 데이터들을 python 내에서 시각화하거나 연산을 통해 데이터들을 전처리 할 수 있는 편리한 모듈입니다.\n- os : 현재 사용하고 있는 컴퓨터에서 사용하는 명령어들을 python에서 사용할 수 있게 하는 모듈로 예를들어 폴더를 이동하거나 폴더를 만들거나 현재 폴더에 있는 파일들을 볼수있습니다.\n- matplotlib : python의 대표적인 시각화 모듈입니다.\n- seaborn : matplotlib을 기반으로 matplotlib 보다 편하게 사용할 수있는 시각화 모듈입니다.\n- tqdm : 돌리고 있는 코드가 어느정도 진행되었는지 확인을 하기위해 사용하는 모듈입니다.\n- pathlib : path들을 편하게 사용할 수 있게 하는 모듈입니다.\n- [PIL](https://ko.wikipedia.org/wiki/Python_Imaging_Library) : 이름은 Python Imaging Library며 이미지 데이터를 다루는 모듈로 이미지를 백터화 or resize or crop 등 다양한 기능들이 있습니다."},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"_kg_hide-input":false},"cell_type":"code","source":"import numpy as np \nimport pandas as pd \nimport os\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom tqdm import tqdm\ntqdm.pandas()\nfrom pathlib import Path\nimport PIL","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(os.listdir(\"../input\"))","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"train_df = pd.read_csv('../input/train.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"del train_df['bbox_x1']\ndel train_df['bbox_x2']\ndel train_df['bbox_y1']\ndel train_df['bbox_y2']","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## class 값 살펴보기\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"print('total class : {}'.format(train_df['class'].nunique()))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"총 196개의 클래스로 구성되어 있네요"},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.countplot(train_df['class'])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"클래스 별 데이터가 얼마나 있는지 확인 하기 위해 seaborn의 countplot을 이용하여 확인해봅니다."},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df['class'].value_counts().head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df['class'].value_counts().tail()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"가장 많은 클래스의 데이터 수는 84개로 119번 class이며 가장 작은 클래스의 데이터 수는 30개로 136번 class입니다."},{"metadata":{},"cell_type":"markdown","source":"## Data Size 살펴보기"},{"metadata":{"trusted":true},"cell_type":"code","source":"def get_img_size(img_id, path):\n            \n    img = PIL.Image.open(f'{path}/{img_id}')\n    \n    return img.size","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"img_dir_path = Path('../input/train/')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df['shape'] = train_df['img_file'].progress_apply(lambda x : get_img_size(x, img_dir_path))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"width_list = [x[0] for x in train_df['shape'].values]\nheight_list = [x[1] for x in train_df['shape'].values]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df['width'] = width_list\ntrain_df['height'] = height_list\ndel (width_list, height_list)\ndel train_df['shape']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df[train_df['width'] == train_df['width'].max()]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df[train_df['width'] == train_df['width'].min()]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df[train_df['height'] == train_df['height'].max()]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df[train_df['height'] == train_df['height'].min()]","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"이미지들 간에 사이즈 차이가 커 보이네요"},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(figsize=(14,6))\nplt.subplot(121)\nsns.distplot(train_df['width'], kde=False, label='width')\nplt.legend()\nplt.title('Image width', fontsize=15)\n\nplt.subplot(122)\nsns.kdeplot(train_df['width'], label='width')\nplt.legend()\nplt.title('Image width KDE Plot', fontsize=15)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(figsize=(14,6))\nplt.subplot(121)\nsns.distplot(train_df['height'], kde=False, label='height')\nplt.legend()\nplt.title('Image width', fontsize=15)\n\nplt.subplot(122)\nsns.kdeplot(train_df['height'], label='height')\nplt.legend()\nplt.title('Image height KDE Plot', fontsize=15)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### 데이터 종횡비 살펴보기"},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df['aspect_ratio'] = train_df['height'] / train_df['width']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(figsize=(14,6))\nplt.subplot(121)\nsns.distplot(train_df['aspect_ratio'], kde=False, label='aspect_ratio')\nplt.legend()\nplt.title('Image aspect_ratio', fontsize=15)\n\nplt.subplot(122)\nsns.kdeplot(train_df['aspect_ratio'], label='aspect_ratio')\nplt.legend()\nplt.title('Image aspect_ratio KDE Plot', fontsize=15)","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}