{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np \nimport pandas as pd\nimport os\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport keras","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%matplotlib inline","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"labels_data = pd.read_csv('../input/labels.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"labels_data.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"labels_data.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"labels_data.tail()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"labels_data['class_name'] = labels_data['attribute_name'].apply(lambda x: x.split('::')[0])\nlabels_data['subclass_name'] = labels_data['attribute_name'].apply(lambda x: x.split('::')[1])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"labels_data.class_name.unique()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.countplot(labels_data.class_name)\nplt.xlabel('Class Name')\nplt.ylabel('Number of subclasses')\nplt.text(x=0, y=300, s=str(labels_data[labels_data.class_name=='culture'].shape[0]), color='white', horizontalalignment='center', size='large', weight='bold')\nplt.text(x=1, y=600, s=str(labels_data[labels_data.class_name=='tag'].shape[0]), color='white', horizontalalignment='center', size='large', weight='bold')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"classes_ordered = labels_data.class_name.apply(lambda x: x=='tag')\nplt.plot(list(range(labels_data.shape[0])), classes_ordered)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"It seems that they are ordered. The culture is placed at the tob then the tag."},{"metadata":{"trusted":true},"cell_type":"code","source":"print('Number of unique attributes = {0}'.format(len(labels_data.subclass_name.unique())))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_data = pd.read_csv('../input/train.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_data.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_data.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Lets see:**\n1. can an image belong to two categories (culture & tag)?\n2. How are the classes distributed? How many images per class? How many classes can an image belong to?"},{"metadata":{"trusted":true},"cell_type":"code","source":"num_images_in_classes = [0]*labels_data.shape[0]\ndef count(record):\n    classes = record.split()\n    for class_ in classes:\n        num_images_in_classes[int(class_)]+=1\n\ntrain_data['attribute_ids'].apply(lambda x: count(x));","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.plot(list(range(labels_data.shape[0])), num_images_in_classes)\nplt.xlabel('Class')\nplt.ylabel('Number of images')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"The dataset is biased. Some classes have many images while other has very few images."},{"metadata":{"trusted":true},"cell_type":"code","source":"len_classes_images = train_data.attribute_ids.apply(lambda x: len(x.split()))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print('Max number of classes for one image = {0}, Min number of classes for one image = {1}'.format(max(len_classes_images), min(len_classes_images)))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.countplot(len_classes_images)\nplt.xticks(list(range(1, 12)))\nplt.xlabel('Number of classes for one image')\nplt.ylabel('Number of images')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"tags = train_data.attribute_ids.apply(lambda x: list(map(lambda y: int(y) >= 398, x.split())))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"all_tags = list(filter(lambda x: len(x) == np.sum(x), tags))\nall_culture = list(filter(lambda x: np.sum(x) == 0, tags))\nprint('Number of images with the culture tag only = {0}'.format(len(all_culture)))\nprint('Number of images without the culture tag = {0}'.format(len(all_tags)))\nprint('Number of images with culture and other tags = {0}'.format(train_data.shape[0]-len(all_tags)-len(all_culture)))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"markdown","source":"To be continued"}],"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}