{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Explore Data Analysis"},{"metadata":{},"cell_type":"markdown","source":"## 1. 데이터셋 불러오기"},{"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\n# for dirname, _, filenames in os.walk('/kaggle/input'):\n#     for filename in filenames:\n#         print(os.path.join(dirname, filename))\n\ncurrent_path = os.getcwd()\ndata_path = os.path.join(current_path, '..', 'input', '2020backofwordrcv')\nprint(os.listdir(data_path))\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## 2. 데이터셋 살펴보기"},{"metadata":{},"cell_type":"markdown","source":"### 2.2. Train 데이터"},{"metadata":{"trusted":true},"cell_type":"code","source":"train_path = os.path.join(data_path, 'traindata')\ntrain_label_list = os.listdir(train_path)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_label_info = {}\n\nfor label in train_label_list:\n    _tmp_label_path = os.path.join(train_path, label)\n    _num_images = len(os.listdir(_tmp_label_path))\n    \n    if label not in train_label_info.keys():\n        train_label_info[label] = _num_images\n        \nnum_show = 10\nprint('Total number of labels: {}'.format(len(train_label_info)))\nprint('Just show {} items {} ...'.format(num_show, list(train_label_info.keys())[:num_show]))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nplt.figure(figsize=(20, 5))\nplt.bar(range(len(train_label_info)), list(train_label_info.values()))\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"- Train 데이터의 label은 총 102개이며, 각 label당 데이터의 개수는 30개로 균등하다."},{"metadata":{"trusted":true},"cell_type":"code","source":"import random\n\nnum_label = len(train_label_info)\nnum_image = train_label_info[train_label_list[0]]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = plt.figure(figsize=(18, 18))\n\nfor i in range(9):\n    ax = fig.add_subplot(3, 3, i + 1)\n    \n    _random_label = random.randint(0, num_label - 1)\n    _random_image = random.randint(0, num_image - 1)\n    \n    _label_path = os.path.join(train_path, train_label_list[_random_label])\n    _image_list = os.listdir(_label_path)\n    _image_path = os.path.join(_label_path, _image_list[_random_image])\n    \n    image = plt.imread(_image_path)\n    plt.imshow(image)\n    \n    _title = '{}, {}'.format(train_label_list[_random_label], _random_image)\n    ax.set_title(_title)\n    ax.axis('off')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### 2.2. Test 데이터"},{"metadata":{"trusted":true},"cell_type":"code","source":"test_path = os.path.join(data_path, 'testdata')\ntest_image_list = os.listdir(test_path)\n\nnum_test_images = len(test_image_list)\nprint('Total number of test images: {}'.format(num_test_images))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = plt.figure(figsize=(18, 18))\n\nfor i in range(9):\n    ax = fig.add_subplot(3, 3, i + 1)\n    \n    _random_image = random.randint(0, num_test_images - 1)\n    _image_path = os.path.join(test_path, test_image_list[_random_image])\n    \n    image = plt.imread(_image_path)\n    plt.imshow(image)\n    \n    _title = '{}'.format(test_image_list[_random_image])\n    ax.set_title(_title)\n    ax.axis('off')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### 2.3. Submission"},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"test_label_path = os.path.join(data_path, \"test_label.csv\")\ntest_label = pd.read_csv(test_label_path)\nprint(test_label.head(5))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## 3. 이미지 크기 살펴보기"},{"metadata":{"trusted":true},"cell_type":"code","source":"cum_h = []\ncum_w = []\n\nfor label_list in train_label_list:\n    _label_path = os.path.join(train_path, label_list)\n    _image_list = os.listdir(_label_path)\n    for image_file in _image_list:\n        _image_path = os.path.join(_label_path, image_file)\n        image = plt.imread(_image_path)\n\n        h, w = image.shape[:2]\n        cum_h.append(h)\n        cum_w.append(w)\n\ncum_h = np.array(cum_h)\ncum_w = np.array(cum_w)\nprint('Avg. height:\\t{:.1f}\\nAvg. width:\\t{:.1f}'.format(np.mean(cum_h), np.mean(cum_w)))\nprint('Median height:\\t{}\\nMedian width:\\t{}'.format(np.median(cum_h), np.median(cum_w)))","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":4}