{"cells":[{"metadata":{"_uuid":"b2e884270293f3663c21d1c9443d848b7a547c84"},"cell_type":"markdown","source":"<h1>What to predict </h1>\n\n We need to predict  protein organelle localization labels for each sample. There are in total 28 different labels present in the dataset. However, the dataset comprises 27 different cell types of highly different morphology, which affect the protein patterns of the different organelles. All image samples are represented by four filters (stored as individual files), the protein of interest (green) plus three cellular landmarks: nucleus (blue), microtubules (red), endoplasmic reticulum (yellow). The green filter should hence be used to predict the label, and the other filters are used as references.\n Lets create a dictionary for labels.\n \n The organelles are visible in green color channel. Blue color marks the nucleus and microtubules are shown in red\n![](http://storage.googleapis.com/kaggle-media/competitions/proteins/description_NACC_cropped_opt.png)"},{"metadata":{"trusted":true,"_uuid":"e3bd7358aadd46b92cad325a8b823ae7f4a65bea"},"cell_type":"code","source":"dicts={\n0:  \"Nucleoplasm\", \n1:  \"Nuclear membrane\",   \n2:  \"Nucleoli\",   \n3:  \"Nucleoli fibrillar center\" ,  \n4:  \"Nuclear speckles\"   ,\n5:  \"Nuclear bodies\"   ,\n6:  \"Endoplasmic reticulum\",   \n7:  \"Golgi apparatus\"   ,\n8:  \"Peroxisomes\"   ,\n9:  \"Endosomes\"   ,\n10:  \"Lysosomes\"   ,\n11:  \"Intermediate filaments\",   \n12:  \"Actin filaments\"   ,\n13:  \"Focal adhesion sites\",   \n14:  \"Microtubules\"   ,\n15:  \"Microtubule ends\",   \n16:  \"Cytokinetic bridge\",   \n17:  \"Mitotic spindle\"   ,\n18:  \"Microtubule organizing center\" ,  \n19:  \"Centrosome\"   ,\n20:  \"Lipid droplets\",   \n21:  \"Plasma membrane\",   \n22:  \"Cell junctions\"  , \n23:  \"Mitochondria\"   ,\n24:  \"Aggresome\"   ,\n25:  \"Cytosol\",\n26:  \"Cytoplasmic bodies\",   \n27:  \"Rods & rings\" \n}","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d9bc40e7062e387e28ea09ba359df9a6109be0c2"},"cell_type":"markdown","source":"<h2>Let's check train csv</h2>"},{"metadata":{"trusted":true,"_uuid":"f9284763de11485240980de5c3c0d4e7cf29685c"},"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nprint(os.listdir(\"../input\"))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"66e86e404e35ee606043a7ebc191cf5919ebb3d6","scrolled":true},"cell_type":"code","source":"df_train = pd.read_csv('../input/train.csv')\ndf_train.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"275c5ad9b242c511a667573ce1a95a14304d0c47"},"cell_type":"code","source":"df_train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"46208066b26d883dc7e687e5c0633823b9b5c1ed"},"cell_type":"code","source":"#cheking for nulls\ndf_train[\"Target\"].isnull().values.sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a5d855b38386e1f2cb41362c74502adeb5ecf5cd"},"cell_type":"code","source":"from collections import Counter, defaultdict\nlabels = df_train['Target'].apply(lambda x: x.split(' '))\nlabels[:5]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4fb1ef2323553c65499ca8a53d6d6444b6d2bc52"},"cell_type":"code","source":"counts = defaultdict(int)\nfor l in labels:\n    for l2 in l:\n        counts[l2] += 1","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"042a26eebf06e6d0f6467a6d74a78bd177cfd782"},"cell_type":"code","source":"strs=[]\nfor count in counts.keys(): strs.append(dicts[int(count)])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"42f248492aac79e9d0d1b66c8851cb27e19907e4"},"cell_type":"code","source":"import seaborn as sns\nsns.set(style=\"whitegrid\")\ndf_count = pd.DataFrame({'ptype': strs,\n     'Count': list(counts.values())})\ndf_count.head()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"6f2a508b72d32b6fd499d5a77624d3ace9a75c52"},"cell_type":"markdown","source":"<h2>Plot plot!</h2>"},{"metadata":{"trusted":true,"_uuid":"4ec86d4abd793c62560027f8d2caba835bec0c89"},"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\n%matplotlib inline\nplt.subplots(figsize=(20,15))\nax = sns.barplot(x=\"ptype\", y=\"Count\", data=df_count)\nfor item in ax.get_xticklabels():\n    item.set_rotation(90)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d87bbe56bf244ea92bd8d8a3e9ac68d91f5df16e"},"cell_type":"markdown","source":"<h2>Lets check a train image </h2>"},{"metadata":{"trusted":true,"_uuid":"e267798dc4b55674251cc8c042890922a9efc189"},"cell_type":"code","source":"import cv2\nfrom PIL import Image","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"75e2a4409bb9f55a8028c68f71295c89a19f318b"},"cell_type":"code","source":"#opening a green image\nimg = Image.open('../input/train/00070df0-bbc3-11e8-b2bc-ac1f6b6435d0_green.png')\nimg","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"dc04137fa19dabb50b888ab336728d3377f1b217"},"cell_type":"code","source":"print(\"Image size :\",img.size)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4d043dd2352855b177defc0e0a5b0e47a01db8f7"},"cell_type":"code","source":"#opening a neuclus blue image\nimg = Image.open('../input/train/00070df0-bbc3-11e8-b2bc-ac1f6b6435d0_blue.png')\nimg","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8682bda972bea2058905851261672fb1c0b8068c"},"cell_type":"code","source":"#opening a microtubles red image\nimg = Image.open('../input/train/00070df0-bbc3-11e8-b2bc-ac1f6b6435d0_red.png')\nimg","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2718232ce1fd0933d4be44616be3ec0dc360f11f"},"cell_type":"code","source":" #opening a endoplasmic reticulum (yellow)\nimg = Image.open('../input/train/00070df0-bbc3-11e8-b2bc-ac1f6b6435d0_yellow.png')\nimg\n    ","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}