{"cells":[{"metadata":{"_uuid":"24ca02d40cbe25ec8272b4dfb5e8c0e62c128b60"},"cell_type":"markdown","source":"***A proposed route to determine which images could be augmented and copied, to help balance the training data set***"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"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 matplotlib.pyplot as plt\n\nimport os\nprint(os.listdir(\"../input\"))","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"#Hot encode the labels to create y_train \nraw = pd.read_csv(\"../input/train.csv\")\nlabels = raw['Target'].str.split()\nlabels = np.asarray(labels.values.tolist())\ny_train = np.zeros([len(raw['Target']),28]).astype(np.int)\nfor i in range(len(labels)):\n    for j in range (len(labels[i])):\n        k = int(labels[i][j])\n        y_train[i][k] = 1","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"99328e3f6022354f7d605bf9ae3ca5ebea3e5a2c"},"cell_type":"code","source":"#Which images have the same label(multi-label class)\nB = np.zeros([len(y_train),len(y_train)]).astype(np.int)\nfor i in range (len(y_train)):\n    A = abs(y_train[i]-y_train)  # square matrix where a row of zeros means the image labels match\n    B[i,:] = np.sum(A,axis=1)  #square matrix of scalars.  A zero value means an image label match.  Each row is for a single image compared against all images\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"950b07c85fac0cc6f8a12fcbab68a2d4c54375f9"},"cell_type":"code","source":"#for each row (an image), how many images exist with the same multi-label\nHMC = np.array([]).astype(np.int)  # a vector of how many counts for each image\nfor i in range(len(B)):\n    HMC = np.append(HMC,((31072-np.count_nonzero(B[i,:]))-1))# for each row, count the number of nonzero values.  Each zero is a duplicate multi-label class\nUnique = np.unique(HMC,return_index=True,return_counts=True)\n\n#now count how many unique classes there are for a given copy count\nUCFAGCC = np.zeros_like(Unique[2])    #Unique Class multi-labels For A Given Copy Count\nfor i in range(len(Unique[2])):\n    if i == 0:\n        UCFAGCC[i] = Unique[2][i]\n    else:\n        UCFAGCC[i] = Unique[2][i]/(Unique[0][i] +1)\n\n#now plot out the answer\nplt.plot(Unique[0],UCFAGCC,'b.')\nplt.xlim(0,120)\nplt.xlabel('Count of How Many Copies with that Unique Class Label')\nplt.ylabel('Number of Unique Class Labels')\nplt. show()\nprint (\"Some Examples\")\nprint (\"There are\", Unique[2][0], \"images in the dataset that have\", Unique[0][0],\"class copies and therefore\",UCFAGCC[0],\"unique class labels that are only found\",Unique[0][0]+1,\"time in X_train\")\nprint (\"There are\", Unique[2][6], \"images in the dataset that have\", Unique[0][6],\"class copies and therefore\",UCFAGCC[6],\"unique class labels that are only found\",Unique[0][6]+1,\"times in X_train\")\nprint (\"There are\", Unique[2][10], \"images in the dataset that have\", Unique[0][10], \"class copies and therefore\",UCFAGCC[10],\"unique class labels that are only found\",Unique[0][10]+1,\"times in X_train\")  \nprint (\"There are\", Unique[2][30], \"images in the dataset that have\", Unique[0][30], \"class copies and therefore\",UCFAGCC[30],\"unique class labels that are only found\",Unique[0][30]+1,\"times in X_train\")\nprint (\"There are\", Unique[2][60], \"images in the dataset that have\", Unique[0][60], \"class copies and therefore\",UCFAGCC[60],\"unique class labels that are only found\",Unique[0][60]+1,\"times in X_train\")\n\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}