In [1]:
%%javascript
IPython.OutputArea.auto_scroll_threshold = 9999;
In [2]:
import pandas as pd
import numpy as np
from collections import Counter
from matplotlib import pyplot as plt
import os
import cv2
%matplotlib inline







def load_filepaths():
    imdir_ideology = 'ideology_image_dataset/'
    ideology_files=os.listdir('ideology_image_dataset/')
    ideology_files_path=[os.path.join(imdir_ideology,file) for file in ideology_files ]
    
    return ideology_files_path

ideology_files_path=load_filepaths()
len(ideology_files_path)

def showClustering(predicted_labels,label):
    label_indexs= np.where(predicted_labels==label)[0]
    print("CLUSTER--> ",label,"TOTAL IMAGES--> ",len(label_indexs))
    if(len(label_indexs)>=500):
        fig=plt.figure(figsize=(10, 400))
        
        
    elif(len(label_indexs)>100 and len(label_indexs)<500):
        fig=plt.figure(figsize=(10, 70))
    elif(len(label_indexs)>=50 and len(label_indexs)<100):
        fig=plt.figure(figsize=(10, 30))
        
    elif(len(label_indexs)>=20 and len(label_indexs)<50):
        fig=plt.figure(figsize=(10, 20))
    
    elif(len(label_indexs)>=0 and len(label_indexs)<20):
        fig=plt.figure(figsize=(10, 8))
    
    for i,index in enumerate(label_indexs):
       
        
        image = cv2.imread(ideology_files_path[index])
        image= cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        
        columns = 4
        rows = np.ceil(len(label_indexs)/float(columns))
        
        fig.add_subplot(rows,columns, i+1)
        plt.imshow(image)
    
   
    plt.show()
In [3]:
results_df=pd.read_csv('image-results-hier/ideology_model_inceptionv3.npy-tsne.csv')
results_df
Out[3]:
Unnamed: 0 n_clusters silhouette calinski davies
0 Birch 891 0.343050 803.531101 0.724632
1 Agglomerative clustering 824 0.423932 981.246694 0.678180
In [ ]:
predicted_Labels=np.load('image-results-hier/ideology_model_inceptionv3.npy-tsne_agg_labels.npy')
unique_labels=set(predicted_Labels)
for label in unique_labels:
    if(label!=-1):
        showClustering(predicted_Labels,label)
CLUSTER-->  0 TOTAL IMAGES-->  4
CLUSTER-->  1 TOTAL IMAGES-->  6
CLUSTER-->  2 TOTAL IMAGES-->  5
CLUSTER-->  3 TOTAL IMAGES-->  7
CLUSTER-->  4 TOTAL IMAGES-->  5
CLUSTER-->  5 TOTAL IMAGES-->  6
CLUSTER-->  6 TOTAL IMAGES-->  6
CLUSTER-->  7 TOTAL IMAGES-->  10
CLUSTER-->  8 TOTAL IMAGES-->  5
CLUSTER-->  9 TOTAL IMAGES-->  7
CLUSTER-->  10 TOTAL IMAGES-->  5
CLUSTER-->  11 TOTAL IMAGES-->  7
CLUSTER-->  12 TOTAL IMAGES-->  7
CLUSTER-->  13 TOTAL IMAGES-->  5
CLUSTER-->  14 TOTAL IMAGES-->  4
CLUSTER-->  15 TOTAL IMAGES-->  5
CLUSTER-->  16 TOTAL IMAGES-->  7
CLUSTER-->  17 TOTAL IMAGES-->  11
CLUSTER-->  18 TOTAL IMAGES-->  5
CLUSTER-->  19 TOTAL IMAGES-->  4
CLUSTER-->  20 TOTAL IMAGES-->  6
CLUSTER-->  21 TOTAL IMAGES-->  5
CLUSTER-->  22 TOTAL IMAGES-->  7
CLUSTER-->  23 TOTAL IMAGES-->  5
CLUSTER-->  24 TOTAL IMAGES-->  5
CLUSTER-->  25 TOTAL IMAGES-->  5
CLUSTER-->  26 TOTAL IMAGES-->  3
CLUSTER-->  27 TOTAL IMAGES-->  6
CLUSTER-->  28 TOTAL IMAGES-->  6
CLUSTER-->  29 TOTAL IMAGES-->  5
CLUSTER-->  30 TOTAL IMAGES-->  6
CLUSTER-->  31 TOTAL IMAGES-->  8
CLUSTER-->  32 TOTAL IMAGES-->  3
CLUSTER-->  33 TOTAL IMAGES-->  6
CLUSTER-->  34 TOTAL IMAGES-->  7
CLUSTER-->  35 TOTAL IMAGES-->  6
CLUSTER-->  36 TOTAL IMAGES-->  5
CLUSTER-->  37 TOTAL IMAGES-->  11
CLUSTER-->  38 TOTAL IMAGES-->  4
CLUSTER-->  39 TOTAL IMAGES-->  8
CLUSTER-->  40 TOTAL IMAGES-->  5
CLUSTER-->  41 TOTAL IMAGES-->  4
CLUSTER-->  42 TOTAL IMAGES-->  6
CLUSTER-->  43 TOTAL IMAGES-->  7
CLUSTER-->  44 TOTAL IMAGES-->  4
CLUSTER-->  45 TOTAL IMAGES-->  5
CLUSTER-->  46 TOTAL IMAGES-->  5
CLUSTER-->  47 TOTAL IMAGES-->  4
CLUSTER-->  48 TOTAL IMAGES-->  5
CLUSTER-->  49 TOTAL IMAGES-->  4
CLUSTER-->  50 TOTAL IMAGES-->  4
CLUSTER-->  51 TOTAL IMAGES-->  3
CLUSTER-->  52 TOTAL IMAGES-->  5
CLUSTER-->  53 TOTAL IMAGES-->  8
CLUSTER-->  54 TOTAL IMAGES-->  5
CLUSTER-->  55 TOTAL IMAGES-->  5
CLUSTER-->  56 TOTAL IMAGES-->  4
CLUSTER-->  57 TOTAL IMAGES-->  7
CLUSTER-->  58 TOTAL IMAGES-->  4
CLUSTER-->  59 TOTAL IMAGES-->  4
CLUSTER-->  60 TOTAL IMAGES-->  5
CLUSTER-->  61 TOTAL IMAGES-->  6
CLUSTER-->  62 TOTAL IMAGES-->  5
CLUSTER-->  63 TOTAL IMAGES-->  4
CLUSTER-->  64 TOTAL IMAGES-->  7
CLUSTER-->  65 TOTAL IMAGES-->  5
CLUSTER-->  66 TOTAL IMAGES-->  4
CLUSTER-->  67 TOTAL IMAGES-->  6
CLUSTER-->  68 TOTAL IMAGES-->  5
CLUSTER-->  69 TOTAL IMAGES-->  4
CLUSTER-->  70 TOTAL IMAGES-->  6
CLUSTER-->  71 TOTAL IMAGES-->  6
CLUSTER-->  72 TOTAL IMAGES-->  5
CLUSTER-->  73 TOTAL IMAGES-->  4
CLUSTER-->  74 TOTAL IMAGES-->  4
CLUSTER-->  75 TOTAL IMAGES-->  6
CLUSTER-->  76 TOTAL IMAGES-->  6
CLUSTER-->  77 TOTAL IMAGES-->  4
CLUSTER-->  78 TOTAL IMAGES-->  9
CLUSTER-->  79 TOTAL IMAGES-->  5
CLUSTER-->  80 TOTAL IMAGES-->  7
CLUSTER-->  81 TOTAL IMAGES-->  4
CLUSTER-->  82 TOTAL IMAGES-->  8
CLUSTER-->  83 TOTAL IMAGES-->  5
CLUSTER-->  84 TOTAL IMAGES-->  4
CLUSTER-->  85 TOTAL IMAGES-->  7
CLUSTER-->  86 TOTAL IMAGES-->  6
CLUSTER-->  87 TOTAL IMAGES-->  4
CLUSTER-->  88 TOTAL IMAGES-->  4
CLUSTER-->  89 TOTAL IMAGES-->  4
CLUSTER-->  90 TOTAL IMAGES-->  6
CLUSTER-->  91 TOTAL IMAGES-->  4
CLUSTER-->  92 TOTAL IMAGES-->  3
CLUSTER-->  93 TOTAL IMAGES-->  3
CLUSTER-->  94 TOTAL IMAGES-->  4
CLUSTER-->  95 TOTAL IMAGES-->  6
CLUSTER-->  96 TOTAL IMAGES-->  5
CLUSTER-->  97 TOTAL IMAGES-->  4
CLUSTER-->  98 TOTAL IMAGES-->  4
CLUSTER-->  99 TOTAL IMAGES-->  5
CLUSTER-->  100 TOTAL IMAGES-->  4
CLUSTER-->  101 TOTAL IMAGES-->  5
CLUSTER-->  102 TOTAL IMAGES-->  4
CLUSTER-->  103 TOTAL IMAGES-->  4
CLUSTER-->  104 TOTAL IMAGES-->  5
CLUSTER-->  105 TOTAL IMAGES-->  8
CLUSTER-->  106 TOTAL IMAGES-->  4
CLUSTER-->  107 TOTAL IMAGES-->  4
CLUSTER-->  108 TOTAL IMAGES-->  5
CLUSTER-->  109 TOTAL IMAGES-->  3
CLUSTER-->  110 TOTAL IMAGES-->  5
CLUSTER-->  111 TOTAL IMAGES-->  5
CLUSTER-->  112 TOTAL IMAGES-->  3
CLUSTER-->  113 TOTAL IMAGES-->  6
CLUSTER-->  114 TOTAL IMAGES-->  5
CLUSTER-->  115 TOTAL IMAGES-->  6
CLUSTER-->  116 TOTAL IMAGES-->  6
CLUSTER-->  117 TOTAL IMAGES-->  5
CLUSTER-->  118 TOTAL IMAGES-->  4
CLUSTER-->  119 TOTAL IMAGES-->  4
CLUSTER-->  120 TOTAL IMAGES-->  6
CLUSTER-->  121 TOTAL IMAGES-->  5
CLUSTER-->  122 TOTAL IMAGES-->  5
CLUSTER-->  123 TOTAL IMAGES-->  6
CLUSTER-->  124 TOTAL IMAGES-->  6
CLUSTER-->  125 TOTAL IMAGES-->  5
CLUSTER-->  126 TOTAL IMAGES-->  4
CLUSTER-->  127 TOTAL IMAGES-->  4
CLUSTER-->  128 TOTAL IMAGES-->  5
CLUSTER-->  129 TOTAL IMAGES-->  5
CLUSTER-->  130 TOTAL IMAGES-->  6
CLUSTER-->  131 TOTAL IMAGES-->  7
CLUSTER-->  132 TOTAL IMAGES-->  3
CLUSTER-->  133 TOTAL IMAGES-->  5
CLUSTER-->  134 TOTAL IMAGES-->  5
CLUSTER-->  135 TOTAL IMAGES-->  6
CLUSTER-->  136 TOTAL IMAGES-->  4
CLUSTER-->  137 TOTAL IMAGES-->  4
CLUSTER-->  138 TOTAL IMAGES-->  5
CLUSTER-->  139 TOTAL IMAGES-->  6
CLUSTER-->  140 TOTAL IMAGES-->  4
CLUSTER-->  141 TOTAL IMAGES-->  5
CLUSTER-->  142 TOTAL IMAGES-->  5
CLUSTER-->  143 TOTAL IMAGES-->  5
CLUSTER-->  144 TOTAL IMAGES-->  4
CLUSTER-->  145 TOTAL IMAGES-->  4
CLUSTER-->  146 TOTAL IMAGES-->  5
CLUSTER-->  147 TOTAL IMAGES-->  3
CLUSTER-->  148 TOTAL IMAGES-->  5
CLUSTER-->  149 TOTAL IMAGES-->  6
CLUSTER-->  150 TOTAL IMAGES-->  6
CLUSTER-->  151 TOTAL IMAGES-->  5
CLUSTER-->  152 TOTAL IMAGES-->  6
CLUSTER-->  153 TOTAL IMAGES-->  4
CLUSTER-->  154 TOTAL IMAGES-->  5
CLUSTER-->  155 TOTAL IMAGES-->  5
CLUSTER-->  156 TOTAL IMAGES-->  5
CLUSTER-->  157 TOTAL IMAGES-->  4
CLUSTER-->  158 TOTAL IMAGES-->  4
CLUSTER-->  159 TOTAL IMAGES-->  6
CLUSTER-->  160 TOTAL IMAGES-->  6
CLUSTER-->  161 TOTAL IMAGES-->  3
CLUSTER-->  162 TOTAL IMAGES-->  5
CLUSTER-->  163 TOTAL IMAGES-->  3
CLUSTER-->  164 TOTAL IMAGES-->  4
CLUSTER-->  165 TOTAL IMAGES-->  6
CLUSTER-->  166 TOTAL IMAGES-->  5
CLUSTER-->  167 TOTAL IMAGES-->  7
CLUSTER-->  168 TOTAL IMAGES-->  5
CLUSTER-->  169 TOTAL IMAGES-->  4
CLUSTER-->  170 TOTAL IMAGES-->  4
CLUSTER-->  171 TOTAL IMAGES-->  6
CLUSTER-->  172 TOTAL IMAGES-->  6
CLUSTER-->  173 TOTAL IMAGES-->  4
CLUSTER-->  174 TOTAL IMAGES-->  5
CLUSTER-->  175 TOTAL IMAGES-->  6
CLUSTER-->  176 TOTAL IMAGES-->  4
CLUSTER-->  177 TOTAL IMAGES-->  5
CLUSTER-->  178 TOTAL IMAGES-->  5
CLUSTER-->  179 TOTAL IMAGES-->  4
CLUSTER-->  180 TOTAL IMAGES-->  4
CLUSTER-->  181 TOTAL IMAGES-->  4
CLUSTER-->  182 TOTAL IMAGES-->  10
CLUSTER-->  183 TOTAL IMAGES-->  4
CLUSTER-->  184 TOTAL IMAGES-->  3
CLUSTER-->  185 TOTAL IMAGES-->  4
CLUSTER-->  186 TOTAL IMAGES-->  3
CLUSTER-->  187 TOTAL IMAGES-->  4
CLUSTER-->  188 TOTAL IMAGES-->  3
CLUSTER-->  189 TOTAL IMAGES-->  4
CLUSTER-->  190 TOTAL IMAGES-->  6
CLUSTER-->  191 TOTAL IMAGES-->  5
CLUSTER-->  192 TOTAL IMAGES-->  3
CLUSTER-->  193 TOTAL IMAGES-->  6
CLUSTER-->  194 TOTAL IMAGES-->  4
CLUSTER-->  195 TOTAL IMAGES-->  4
CLUSTER-->  196 TOTAL IMAGES-->  4
CLUSTER-->  197 TOTAL IMAGES-->  4
CLUSTER-->  198 TOTAL IMAGES-->  6
CLUSTER-->  199 TOTAL IMAGES-->  3
CLUSTER-->  200 TOTAL IMAGES-->  5
CLUSTER-->  201 TOTAL IMAGES-->  3
CLUSTER-->  202 TOTAL IMAGES-->  4
CLUSTER-->  203 TOTAL IMAGES-->  3
CLUSTER-->  204 TOTAL IMAGES-->  4
CLUSTER-->  205 TOTAL IMAGES-->  3
CLUSTER-->  206 TOTAL IMAGES-->  4
CLUSTER-->  207 TOTAL IMAGES-->  5
CLUSTER-->  208 TOTAL IMAGES-->  4
CLUSTER-->  209 TOTAL IMAGES-->  4
CLUSTER-->  210 TOTAL IMAGES-->  3
CLUSTER-->  211 TOTAL IMAGES-->  3
CLUSTER-->  212 TOTAL IMAGES-->  4
CLUSTER-->  213 TOTAL IMAGES-->  5
CLUSTER-->  214 TOTAL IMAGES-->  4
CLUSTER-->  215 TOTAL IMAGES-->  2
CLUSTER-->  216 TOTAL IMAGES-->  4
CLUSTER-->  217 TOTAL IMAGES-->  3
CLUSTER-->  218 TOTAL IMAGES-->  5
CLUSTER-->  219 TOTAL IMAGES-->  4
CLUSTER-->  220 TOTAL IMAGES-->  4
CLUSTER-->  221 TOTAL IMAGES-->  3
CLUSTER-->  222 TOTAL IMAGES-->  5
CLUSTER-->  223 TOTAL IMAGES-->  3
CLUSTER-->  224 TOTAL IMAGES-->  6
CLUSTER-->  225 TOTAL IMAGES-->  4
CLUSTER-->  226 TOTAL IMAGES-->  3
CLUSTER-->  227 TOTAL IMAGES-->  5
CLUSTER-->  228 TOTAL IMAGES-->  6
CLUSTER-->  229 TOTAL IMAGES-->  3
CLUSTER-->  230 TOTAL IMAGES-->  4
CLUSTER-->  231 TOTAL IMAGES-->  3
CLUSTER-->  232 TOTAL IMAGES-->  4
CLUSTER-->  233 TOTAL IMAGES-->  5
CLUSTER-->  234 TOTAL IMAGES-->  4
CLUSTER-->  235 TOTAL IMAGES-->  4
CLUSTER-->  236 TOTAL IMAGES-->  6
CLUSTER-->  237 TOTAL IMAGES-->  3
CLUSTER-->  238 TOTAL IMAGES-->  4
CLUSTER-->  239 TOTAL IMAGES-->  3
CLUSTER-->  240 TOTAL IMAGES-->  4
CLUSTER-->  241 TOTAL IMAGES-->  3
CLUSTER-->  242 TOTAL IMAGES-->  8
CLUSTER-->  243 TOTAL IMAGES-->  4
CLUSTER-->  244 TOTAL IMAGES-->  4
CLUSTER-->  245 TOTAL IMAGES-->  4
CLUSTER-->  246 TOTAL IMAGES-->  3
CLUSTER-->  247 TOTAL IMAGES-->  4
CLUSTER-->  248 TOTAL IMAGES-->  7
CLUSTER-->  249 TOTAL IMAGES-->  4
CLUSTER-->  250 TOTAL IMAGES-->  4
CLUSTER-->  251 TOTAL IMAGES-->  5
CLUSTER-->  252 TOTAL IMAGES-->  6
CLUSTER-->  253 TOTAL IMAGES-->  4
CLUSTER-->  254 TOTAL IMAGES-->  3
CLUSTER-->  255 TOTAL IMAGES-->  3
CLUSTER-->  256 TOTAL IMAGES-->  3
CLUSTER-->  257 TOTAL IMAGES-->  5
CLUSTER-->  258 TOTAL IMAGES-->  5
CLUSTER-->  259 TOTAL IMAGES-->  4
CLUSTER-->  260 TOTAL IMAGES-->  4
CLUSTER-->  261 TOTAL IMAGES-->  3
CLUSTER-->  262 TOTAL IMAGES-->  5
CLUSTER-->  263 TOTAL IMAGES-->  4
CLUSTER-->  264 TOTAL IMAGES-->  6
CLUSTER-->  265 TOTAL IMAGES-->  3
CLUSTER-->  266 TOTAL IMAGES-->  3
CLUSTER-->  267 TOTAL IMAGES-->  3
CLUSTER-->  268 TOTAL IMAGES-->  4
CLUSTER-->  269 TOTAL IMAGES-->  3
CLUSTER-->  270 TOTAL IMAGES-->  3
CLUSTER-->  271 TOTAL IMAGES-->  5
CLUSTER-->  272 TOTAL IMAGES-->  3
CLUSTER-->  273 TOTAL IMAGES-->  4
CLUSTER-->  274 TOTAL IMAGES-->  4
CLUSTER-->  275 TOTAL IMAGES-->  4
CLUSTER-->  276 TOTAL IMAGES-->  4
CLUSTER-->  277 TOTAL IMAGES-->  4
CLUSTER-->  278 TOTAL IMAGES-->  5
CLUSTER-->  279 TOTAL IMAGES-->  3
CLUSTER-->  280 TOTAL IMAGES-->  4
CLUSTER-->  281 TOTAL IMAGES-->  4
CLUSTER-->  282 TOTAL IMAGES-->  2
CLUSTER-->  283 TOTAL IMAGES-->  4
CLUSTER-->  284 TOTAL IMAGES-->  2
CLUSTER-->  285 TOTAL IMAGES-->  4
CLUSTER-->  286 TOTAL IMAGES-->  3
CLUSTER-->  287 TOTAL IMAGES-->  4
CLUSTER-->  288 TOTAL IMAGES-->  3
CLUSTER-->  289 TOTAL IMAGES-->  3
In [ ]:
predicted_Labels=np.load('image-results-hier/ideology_model_inceptionv3.npy-tsne_birch_labels.npy')
unique_labels=set(predicted_Labels)
for label in unique_labels:
    if(label!=-1):
        showClustering(predicted_Labels,label)