In [1]:
%%bash 
jupyter nbconvert --to html Exploring_Original_Dataset.ipynb && mv Exploring_Original_Dataset.html ../notebook_htmls/Exploring_Original_Dataset_v1.html


[NbConvertApp] Converting notebook Exploring_Original_Dataset.ipynb to html
[NbConvertApp] Writing 869974 bytes to Exploring_Original_Dataset.html

Setup


In [174]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import pickle
from IPython.core.debugger import Tracer
import seaborn as sns
%matplotlib inline

Running the examples

Example 1


In [17]:
import tensorflow as tf
import sklearn
import h5py
import keras
from keras.preprocessing import image
from resnet50 import ResNet50
from imagenet_utils import preprocess_input, decode_predictions

In [18]:
model = ResNet50(weights='imagenet')


K.image_dim_ordering: tf

In [19]:
from IPython.display import SVG
from keras.utils.vis_utils import model_to_dot

SVG(model_to_dot(model).create(prog='dot', format='svg'))


Out[19]:
G 4716089680 input_2: InputLayer 4715212880 zero_padding2d_2: ZeroPadding2D 4716089680->4715212880 4762688848 conv1: Conv2D 4715212880->4762688848 4762688912 bn_conv1: BatchNormalization 4762688848->4762688912 4763393424 activation_50: Activation 4762688912->4763393424 4762881168 max_pooling2d_2: MaxPooling2D 4763393424->4762881168 4763474960 res2a_branch2a: Conv2D 4762881168->4763474960 4765572368 res2a_branch1: Conv2D 4762881168->4765572368 4763712912 bn2a_branch2a: BatchNormalization 4763474960->4763712912 4763916752 activation_51: Activation 4763712912->4763916752 4764315408 res2a_branch2b: Conv2D 4763916752->4764315408 4764051280 bn2a_branch2b: BatchNormalization 4764315408->4764051280 4764528464 activation_52: Activation 4764051280->4764528464 4765019280 res2a_branch2c: Conv2D 4764528464->4765019280 4765082576 bn2a_branch2c: BatchNormalization 4765019280->4765082576 4765618768 bn2a_branch1: BatchNormalization 4765572368->4765618768 4766188496 merge_17: Merge 4765082576->4766188496 4765618768->4766188496 4766244944 activation_53: Activation 4766188496->4766244944 4766321168 res2b_branch2a: Conv2D 4766244944->4766321168 4768127248 merge_18: Merge 4766244944->4768127248 4766655056 bn2b_branch2a: BatchNormalization 4766321168->4766655056 4766805584 activation_54: Activation 4766655056->4766805584 4767019792 res2b_branch2b: Conv2D 4766805584->4767019792 4766948304 bn2b_branch2b: BatchNormalization 4767019792->4766948304 4767507664 activation_55: Activation 4766948304->4767507664 4767510480 res2b_branch2c: Conv2D 4767507664->4767510480 4767891792 bn2b_branch2c: BatchNormalization 4767510480->4767891792 4767891792->4768127248 4768534416 activation_56: Activation 4768127248->4768534416 4768200400 res2c_branch2a: Conv2D 4768534416->4768200400 4771650384 merge_19: Merge 4768534416->4771650384 4768754896 bn2c_branch2a: BatchNormalization 4768200400->4768754896 4768906768 activation_57: Activation 4768754896->4768906768 4768835536 res2c_branch2b: Conv2D 4768906768->4768835536 4768974032 bn2c_branch2b: BatchNormalization 4768835536->4768974032 4771049104 activation_58: Activation 4768974032->4771049104 4771433616 res2c_branch2c: Conv2D 4771049104->4771433616 4771165072 bn2c_branch2c: BatchNormalization 4771433616->4771165072 4771165072->4771650384 4772044624 activation_59: Activation 4771650384->4772044624 4771726224 res3a_branch2a: Conv2D 4772044624->4771726224 4773842320 res3a_branch1: Conv2D 4772044624->4773842320 4772129360 bn3a_branch2a: BatchNormalization 4771726224->4772129360 4772353040 activation_60: Activation 4772129360->4772353040 4772355856 res3a_branch2b: Conv2D 4772353040->4772355856 4772737168 bn3a_branch2b: BatchNormalization 4772355856->4772737168 4772975760 activation_61: Activation 4772737168->4772975760 4773629648 res3a_branch2c: Conv2D 4772975760->4773629648 4773107152 bn3a_branch2c: BatchNormalization 4773629648->4773107152 4773930448 bn3a_branch1: BatchNormalization 4773842320->4773930448 4774614608 merge_20: Merge 4773107152->4774614608 4773930448->4774614608 4774557456 activation_62: Activation 4774614608->4774557456 4774558992 res3b_branch2a: Conv2D 4774557456->4774558992 4776507728 merge_21: Merge 4774557456->4776507728 4774951760 bn3b_branch2a: BatchNormalization 4774558992->4774951760 4775191504 activation_63: Activation 4774951760->4775191504 4775579152 res3b_branch2b: Conv2D 4775191504->4775579152 4775326992 bn3b_branch2b: BatchNormalization 4775579152->4775326992 4775800016 activation_64: Activation 4775326992->4775800016 4775881424 res3b_branch2c: Conv2D 4775800016->4775881424 4775956048 bn3b_branch2c: BatchNormalization 4775881424->4775956048 4775956048->4776507728 4776507984 activation_65: Activation 4776507728->4776507984 4776650320 res3c_branch2a: Conv2D 4776507984->4776650320 4778446096 merge_22: Merge 4776507984->4778446096 4776892624 bn3c_branch2a: BatchNormalization 4776650320->4776892624 4777126352 activation_66: Activation 4776892624->4777126352 4777529104 res3c_branch2b: Conv2D 4777126352->4777529104 4777260880 bn3c_branch2b: BatchNormalization 4777529104->4777260880 4777742160 activation_67: Activation 4777260880->4777742160 4777897104 res3c_branch2c: Conv2D 4777742160->4777897104 4777968592 bn3c_branch2c: BatchNormalization 4777897104->4777968592 4777968592->4778446096 4778834704 activation_68: Activation 4778446096->4778834704 4778504784 res3d_branch2a: Conv2D 4778834704->4778504784 4786057040 merge_23: Merge 4778834704->4786057040 4778926992 bn3d_branch2a: BatchNormalization 4778504784->4778926992 4779068432 activation_69: Activation 4778926992->4779068432 4779137552 res3d_branch2b: Conv2D 4779068432->4779137552 4779208528 bn3d_branch2b: BatchNormalization 4779137552->4779208528 4779759760 activation_70: Activation 4779208528->4779759760 4779761296 res3d_branch2c: Conv2D 4779759760->4779761296 4780146832 bn3d_branch2c: BatchNormalization 4779761296->4780146832 4780146832->4786057040 4786449744 activation_71: Activation 4786057040->4786449744 4786111632 res4a_branch2a: Conv2D 4786449744->4786111632 4787992848 res4a_branch1: Conv2D 4786449744->4787992848 4786521552 bn4a_branch2a: BatchNormalization 4786111632->4786521552 4786671184 activation_72: Activation 4786521552->4786671184 4786885392 res4a_branch2b: Conv2D 4786671184->4786885392 4786813904 bn4a_branch2b: BatchNormalization 4786885392->4786813904 4787373264 activation_73: Activation 4786813904->4787373264 4787376080 res4a_branch2c: Conv2D 4787373264->4787376080 4787769680 bn4a_branch2c: BatchNormalization 4787376080->4787769680 4788066000 bn4a_branch1: BatchNormalization 4787992848->4788066000 4788616208 merge_24: Merge 4787769680->4788616208 4788066000->4788616208 4788693648 activation_74: Activation 4788616208->4788693648 4788838544 res4b_branch2a: Conv2D 4788693648->4788838544 4790562192 merge_25: Merge 4788693648->4790562192 4789098192 bn4b_branch2a: BatchNormalization 4788838544->4789098192 4789322768 activation_75: Activation 4789098192->4789322768 4789325584 res4b_branch2b: Conv2D 4789322768->4789325584 4789710992 bn4b_branch2b: BatchNormalization 4789325584->4789710992 4789945488 activation_76: Activation 4789710992->4789945488 4790337232 res4b_branch2c: Conv2D 4789945488->4790337232 4790085072 bn4b_branch2c: BatchNormalization 4790337232->4790085072 4790085072->4790562192 4790784592 activation_77: Activation 4790562192->4790784592 4790642128 res4c_branch2a: Conv2D 4790784592->4790642128 4792663376 merge_26: Merge 4790784592->4792663376 4791047248 bn4c_branch2a: BatchNormalization 4790642128->4791047248 4791270864 activation_78: Activation 4791047248->4791270864 4791659472 res4c_branch2b: Conv2D 4791270864->4791659472 4791411408 bn4c_branch2b: BatchNormalization 4791659472->4791411408 4791884432 activation_79: Activation 4791411408->4791884432 4792295376 res4c_branch2c: Conv2D 4791884432->4792295376 4792031248 bn4c_branch2c: BatchNormalization 4792295376->4792031248 4792031248->4792663376 4792602320 activation_80: Activation 4792663376->4792602320 4792600592 res4d_branch2a: Conv2D 4792602320->4792600592 4794542416 merge_27: Merge 4792602320->4794542416 4792993424 bn4d_branch2a: BatchNormalization 4792600592->4792993424 4793226192 activation_81: Activation 4792993424->4793226192 4793617936 res4d_branch2b: Conv2D 4793226192->4793617936 4793357584 bn4d_branch2b: BatchNormalization 4793617936->4793357584 4793838800 activation_82: Activation 4793357584->4793838800 4793907920 res4d_branch2c: Conv2D 4793838800->4793907920 4793982544 bn4d_branch2c: BatchNormalization 4793907920->4793982544 4793982544->4794542416 4794542672 activation_83: Activation 4794542416->4794542672 4794680912 res4e_branch2a: Conv2D 4794542672->4794680912 4796837136 merge_28: Merge 4794542672->4796837136 4794939600 bn4e_branch2a: BatchNormalization 4794680912->4794939600 4795161040 activation_84: Activation 4794939600->4795161040 4795920144 res4e_branch2b: Conv2D 4795161040->4795920144 4795299664 bn4e_branch2b: BatchNormalization 4795920144->4795299664 4796141392 activation_85: Activation 4795299664->4796141392 4796288144 res4e_branch2c: Conv2D 4796141392->4796288144 4796355536 bn4e_branch2c: BatchNormalization 4796288144->4796355536 4796355536->4796837136 4797233936 activation_86: Activation 4796837136->4797233936 4796912208 res4f_branch2a: Conv2D 4797233936->4796912208 4798795600 merge_29: Merge 4797233936->4798795600 4797318032 bn4f_branch2a: BatchNormalization 4796912208->4797318032 4797471760 activation_87: Activation 4797318032->4797471760 4797544976 res4f_branch2b: Conv2D 4797471760->4797544976 4797607760 bn4f_branch2b: BatchNormalization 4797544976->4797607760 4798163088 activation_88: Activation 4797607760->4798163088 4798164624 res4f_branch2c: Conv2D 4798163088->4798164624 4798558352 bn4f_branch2c: BatchNormalization 4798164624->4798558352 4798558352->4798795600 4799184208 activation_89: Activation 4798795600->4799184208 4798858384 res5a_branch2a: Conv2D 4799184208->4798858384 4800731408 res5a_branch1: Conv2D 4799184208->4800731408 4799268304 bn5a_branch2a: BatchNormalization 4798858384->4799268304 4799413840 activation_90: Activation 4799268304->4799413840 4799632144 res5a_branch2b: Conv2D 4799413840->4799632144 4799552464 bn5a_branch2b: BatchNormalization 4799632144->4799552464 4800120016 activation_91: Activation 4799552464->4800120016 4800122832 res5a_branch2c: Conv2D 4800120016->4800122832 4800508240 bn5a_branch2c: BatchNormalization 4800122832->4800508240 4801136272 bn5a_branch1: BatchNormalization 4800731408->4801136272 4801362960 merge_30: Merge 4800508240->4801362960 4801136272->4801362960 4801444496 activation_92: Activation 4801362960->4801444496 4801593488 res5b_branch2a: Conv2D 4801444496->4801593488 4803300752 merge_31: Merge 4801444496->4803300752 4801840848 bn5b_branch2a: BatchNormalization 4801593488->4801840848 4802081808 activation_93: Activation 4801840848->4802081808 4802084624 res5b_branch2b: Conv2D 4802081808->4802084624 4802457744 bn5b_branch2b: BatchNormalization 4802084624->4802457744 4802684048 activation_94: Activation 4802457744->4802684048 4803079888 res5b_branch2c: Conv2D 4802684048->4803079888 4802827728 bn5b_branch2c: BatchNormalization 4803079888->4802827728 4802827728->4803300752 4803527248 activation_95: Activation 4803300752->4803527248 4803380688 res5c_branch2a: Conv2D 4803527248->4803380688 4805397840 merge_32: Merge 4803527248->4805397840 4803781712 bn5c_branch2a: BatchNormalization 4803380688->4803781712 4804021712 activation_96: Activation 4803781712->4804021712 4804402128 res5c_branch2b: Conv2D 4804021712->4804402128 4804149968 bn5c_branch2b: BatchNormalization 4804402128->4804149968 4804622992 activation_97: Activation 4804149968->4804622992 4805029840 res5c_branch2c: Conv2D 4804622992->4805029840 4804769808 bn5c_branch2c: BatchNormalization 4805029840->4804769808 4804769808->4805397840 4805332688 activation_98: Activation 4805397840->4805332688 4805330960 avg_pool: AveragePooling2D 4805332688->4805330960 4805730000 flatten_1: Flatten 4805330960->4805730000 4805885200 fc1000: Dense 4805730000->4805885200

In [8]:
#model.

In [19]:
img_path = 'img/euro/EUROMODA-U125256-39-5.jpg'
img = image.load_img(img_path, target_size=(224, 224))
img


Out[19]:

In [20]:
x = image.img_to_array(img)
x.shape


Out[20]:
(224, 224, 3)

In [21]:
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

In [23]:
x.shape


Out[23]:
(1, 224, 224, 3)

In [27]:
plt.imshow(x[0,:,:,0])


Out[27]:
<matplotlib.image.AxesImage at 0x11c3eb0d0>

In [31]:
preds = model.predict(x)

In [54]:
plt.plot(preds.T)


Out[54]:
[<matplotlib.lines.Line2D at 0x11fe35d90>]

In [32]:
preds.shape


Out[32]:
(1, 1000)

In [33]:
print('Predicted:', decode_predictions(preds))
# print: [[u'n02504458', u'African_elephant']]


('Predicted:', [[(u'n03770439', u'miniskirt', 0.70049727), (u'n03534580', u'hoopskirt', 0.14744078), (u'n03450230', u'gown', 0.024755424), (u'n03866082', u'overskirt', 0.023801861), (u'n03594734', u'jean', 0.014014562)]])

Example 2


In [2]:
from vgg16 import VGG16
from keras.preprocessing import image
from imagenet_utils import preprocess_input

model = VGG16(weights='imagenet', include_top=False)


vgg16.py:79: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(64, (3, 3), padding="same", activation="relu", name="block1_conv1")`
  x = Convolution2D(64, 3, 3, activation='relu', border_mode='same', name='block1_conv1')(img_input)
vgg16.py:80: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(64, (3, 3), padding="same", activation="relu", name="block1_conv2")`
  x = Convolution2D(64, 3, 3, activation='relu', border_mode='same', name='block1_conv2')(x)
vgg16.py:84: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(128, (3, 3), padding="same", activation="relu", name="block2_conv1")`
  x = Convolution2D(128, 3, 3, activation='relu', border_mode='same', name='block2_conv1')(x)
vgg16.py:85: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(128, (3, 3), padding="same", activation="relu", name="block2_conv2")`
  x = Convolution2D(128, 3, 3, activation='relu', border_mode='same', name='block2_conv2')(x)
vgg16.py:89: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (3, 3), padding="same", activation="relu", name="block3_conv1")`
  x = Convolution2D(256, 3, 3, activation='relu', border_mode='same', name='block3_conv1')(x)
vgg16.py:90: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (3, 3), padding="same", activation="relu", name="block3_conv2")`
  x = Convolution2D(256, 3, 3, activation='relu', border_mode='same', name='block3_conv2')(x)
vgg16.py:91: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (3, 3), padding="same", activation="relu", name="block3_conv3")`
  x = Convolution2D(256, 3, 3, activation='relu', border_mode='same', name='block3_conv3')(x)
vgg16.py:95: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(512, (3, 3), padding="same", activation="relu", name="block4_conv1")`
  x = Convolution2D(512, 3, 3, activation='relu', border_mode='same', name='block4_conv1')(x)
vgg16.py:96: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(512, (3, 3), padding="same", activation="relu", name="block4_conv2")`
  x = Convolution2D(512, 3, 3, activation='relu', border_mode='same', name='block4_conv2')(x)
vgg16.py:97: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(512, (3, 3), padding="same", activation="relu", name="block4_conv3")`
  x = Convolution2D(512, 3, 3, activation='relu', border_mode='same', name='block4_conv3')(x)
vgg16.py:101: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(512, (3, 3), padding="same", activation="relu", name="block5_conv1")`
  x = Convolution2D(512, 3, 3, activation='relu', border_mode='same', name='block5_conv1')(x)
vgg16.py:102: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(512, (3, 3), padding="same", activation="relu", name="block5_conv2")`
  x = Convolution2D(512, 3, 3, activation='relu', border_mode='same', name='block5_conv2')(x)
vgg16.py:103: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(512, (3, 3), padding="same", activation="relu", name="block5_conv3")`
  x = Convolution2D(512, 3, 3, activation='relu', border_mode='same', name='block5_conv3')(x)
K.image_dim_ordering: tf

In [3]:
img_path = '1360x.jpeg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
x.shape


Out[3]:
(1, 224, 224, 3)

In [4]:
features = model.predict(x)
print features


[[[[  0.           0.           0.         ...,   0.           0.           0.        ]
   [  0.           0.           0.         ...,   0.           0.           0.        ]
   [  0.           0.           0.         ...,   0.           0.           0.        ]
   ..., 
   [  0.           0.           0.         ...,   0.           0.           0.        ]
   [  0.           0.           0.         ...,   0.           3.66635823
      0.        ]
   [  0.           0.           0.         ...,   0.          20.83097458
      0.        ]]

  [[  0.           0.           0.         ...,   0.           0.           0.        ]
   [  0.           0.           0.         ...,   0.           0.           0.        ]
   [  0.           0.           0.         ...,   0.           0.           0.        ]
   ..., 
   [  0.           0.           0.         ...,   0.           0.           0.        ]
   [  0.           0.           0.         ...,   0.           0.           0.        ]
   [  0.           0.           0.         ...,   0.           8.32832527
      0.        ]]

  [[  0.           0.           0.         ...,   0.           4.39247799
      0.        ]
   [  0.           0.           0.         ...,   0.           0.62454587
      0.        ]
   [  0.           0.           0.         ...,   0.           0.           0.        ]
   ..., 
   [  0.           0.           0.         ...,   0.           0.           0.        ]
   [  0.           0.           0.         ...,   0.           0.           0.        ]
   [  0.          11.68005753   0.         ...,   0.           0.           0.        ]]

  ..., 
  [[  0.           0.           0.         ...,   0.           0.           0.        ]
   [  0.           0.           0.         ...,   0.           7.66379595
      0.        ]
   [  0.           0.          14.49871254 ...,  15.69186306   0.86040729
     52.58253098]
   ..., 
   [  0.           0.          44.04948807 ...,   0.7248171    0.
     74.18131256]
   [  0.           0.           0.         ...,   0.           0.           0.        ]
   [  0.           0.           0.         ...,   0.           0.           0.        ]]

  [[  0.           0.           0.         ...,   0.           0.           0.        ]
   [  0.           0.           0.         ...,   0.          11.48617077
      0.        ]
   [ 19.1120472    0.          10.74147511 ...,   0.           5.01728582
      0.40190187]
   ..., 
   [  0.           0.           3.63383579 ...,   0.           0.           0.        ]
   [  0.           0.           0.         ...,   0.           0.           0.        ]
   [  0.           0.           0.         ...,   0.           0.           0.        ]]

  [[  0.           0.           0.         ...,   0.           0.           0.        ]
   [  0.           0.           0.         ...,   0.           0.           0.        ]
   [  0.           0.           0.         ...,   0.           0.           0.        ]
   ..., 
   [  0.           0.           0.         ...,   0.           0.           0.        ]
   [  0.           0.           0.         ...,   0.           0.           0.        ]
   [  0.           0.           0.         ...,   0.           0.           0.        ]]]]

In [5]:
features.shape


Out[5]:
(1, 7, 7, 512)

In [8]:
## save out instead 
# from keras.utils import plot_model
# plot_model(model, to_file='model.png')

In [7]:
from IPython.display import SVG
from keras.utils.vis_utils import model_to_dot

SVG(model_to_dot(model).create(prog='dot', format='svg'))


Out[7]:
G 4673336336 input_1: InputLayer 4601468432 block1_conv1: Conv2D 4673336336->4601468432 4673481296 block1_conv2: Conv2D 4601468432->4673481296 4673337808 block1_pool: MaxPooling2D 4673481296->4673337808 4673339344 block2_conv1: Conv2D 4673337808->4673339344 4673562128 block2_conv2: Conv2D 4673339344->4673562128 4673717328 block2_pool: MaxPooling2D 4673562128->4673717328 4673932176 block3_conv1: Conv2D 4673717328->4673932176 4673856720 block3_conv2: Conv2D 4673932176->4673856720 4674003664 block3_conv3: Conv2D 4673856720->4674003664 4674139088 block3_pool: MaxPooling2D 4674003664->4674139088 4674215824 block4_conv1: Conv2D 4674139088->4674215824 4674362512 block4_conv2: Conv2D 4674215824->4674362512 4674417296 block4_conv3: Conv2D 4674362512->4674417296 4674556752 block4_pool: MaxPooling2D 4674417296->4674556752 4674633552 block5_conv1: Conv2D 4674556752->4674633552 4674699664 block5_conv2: Conv2D 4674633552->4674699664 4674837200 block5_conv3: Conv2D 4674699664->4674837200 4674980176 block5_pool: MaxPooling2D 4674837200->4674980176

Example 3


In [9]:
from vgg19 import VGG19
from keras.preprocessing import image
from imagenet_utils import preprocess_input
from keras.models import Model

In [12]:
base_model.input


Out[12]:
<tf.Tensor 'input_2:0' shape=(?, ?, ?, 3) dtype=float32>

In [15]:
base_model.get_layer('block5_pool')
# the layers appear to be keras objects.


Out[15]:
<keras.layers.pooling.MaxPooling2D at 0x1178db490>

In [16]:
base_model.get_layer('block5_pool').output
# input and output appear to be tensorflow tensors.


Out[16]:
<tf.Tensor 'block5_pool_1/MaxPool:0' shape=(?, ?, ?, 512) dtype=float32>

In [17]:
base_model = VGG19(include_top=False, weights='imagenet')
model = Model(input=base_model.input, output=base_model.get_layer('block5_pool').output) 
# this Model creates a model based on some input tensor and some output tensor. 
# here we've taken the base_model, and grabbed it's input layer, and it's 5th output layer, 
# and created a new model with just those layers or is it all the layers inbetween


K.image_dim_ordering: tf
/Users/chris/anaconda/envs/virtenv/lib/python2.7/site-packages/ipykernel_launcher.py:2: UserWarning: Update your `Model` call to the Keras 2 API: `Model(outputs=Tensor("bl..., inputs=Tensor("in...)`
  

In [18]:
#img_path = '1360x.jpeg'
img_path = 'img/euro/EUROMODA-U125256-39-5.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

In [19]:
img


Out[19]:

In [20]:
block4_pool_features = model.predict(x) # now we predict based on those layers

In [22]:
block4_pool_features.shape # same shape as before.


Out[22]:
(1, 7, 7, 512)

In [26]:
np.shape(block4_pool_features.tolist()[0][0])


Out[26]:
(7, 512)

In [29]:
import itertools
flattened_list  = list(itertools.chain(*block4_pool_features.tolist()[0][0])) # * will unpack 


for item in flattened_list: print item


0.0
0.0
0.0
0.0
3.34507751465
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
1.08420681953
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
1.28566038609
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
2.05428695679
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
19.9965000153
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.138743013144
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.63628256321
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.410997182131
0.0
0.0
0.0
0.0
0.0
0.0
34.7835845947
50.9635314941
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
10.4430122375
0.0
0.0
0.0
0.0
0.0
8.71476078033
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
22.9215202332
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
3.63695907593
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
4.97389221191
0.0
0.0
0.0
0.0
0.0
0.0
0.0
3.71016025543
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
4.0118970871
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
2.9739947319
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
28.3929080963
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
7.42865753174
0.0
0.0
0.0
29.7198123932
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.824616670609
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
3.14881467819
0.0
0.0
0.0
0.0
0.0
0.0
0.0
1.20848083496
0.0
0.0
0.0
0.0
0.0
0.0582658648491
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
4.50704860687
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
4.97218322754
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
3.46980547905
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
4.82590293884
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.732009768486
0.0
0.0
0.0
0.0
0.0
0.0
0.0
9.96099281311
2.5997979641
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
56.5265769958
49.1599388123
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
13.2407531738
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
13.9327936172
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.763867676258
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
2.8117480278
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
16.2826881409
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
42.3403129578
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
2.32468104362
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
3.0589299202
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
8.47569561005
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
15.3325586319
0.0
0.0
0.0
21.0963554382
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
4.21525764465
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
92.593963623
0.0
0.0
0.0
0.0
0.0
28.066532135
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
38.8776855469
0.0
0.0
0.0
0.0
0.0
26.4570732117
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
4.74932575226
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.271937191486
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
8.09280204773
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
13.4929256439
0.0
0.0
0.0
0.0
0.0
10.5604553223
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
4.63319826126
0.0
0.0
0.0
0.0
0.0
2.6916642189
0.0
0.0
0.0
1.91495966911
28.8477325439
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
8.05315589905
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0743232220411
77.6644287109
0.0
0.0
0.0
0.0
0.0
0.0
6.71459770203
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
21.4034099579
0.0
0.0
0.0
0.0
0.0
0.0
0.0
35.3534317017
32.453868866
65.0779266357
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
12.6202526093
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
8.53886699677
0.0
0.0
0.0
0.0
0.0
0.0
0.0
10.0148439407
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
10.6749200821
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
18.1256637573
0.0
0.0
0.0
0.0
0.0
19.6124839783
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
23.5542392731
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
24.6121482849
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
29.8304748535
0.0
0.0
24.3619728088
0.0
0.0
0.0
0.0
0.0
0.0
0.0
69.5991897583
0.0
0.0
0.0
0.0
1.17105019093
0.0
0.0
0.0
75.9447479248
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
5.30015611649
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
13.8715991974
0.0
9.53807449341
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
7.60665893555
0.0
0.0
0.0
0.0
6.12402009964
0.0
0.0
0.0
0.0
0.0
0.0
9.73948669434
0.0
0.0
0.0
6.96145153046
0.0
0.0
0.0
0.0
0.0
0.0
39.6815643311
0.0
0.0
0.0
0.870773732662
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
13.3910980225
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.749507546425
7.82311630249
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
30.3895492554
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
152.235427856
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
14.0657806396
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
11.9517593384
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
9.32207965851
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
30.0635242462
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
65.5289230347
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
8.00426197052
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
126.303497314
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
28.7288341522
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
21.152759552
0.0
0.0
0.0
0.0
0.0
0.0
0.0
117.871810913
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
85.579536438
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
3.44899511337
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
141.224502563
0.0
0.0
0.0
0.0
0.0
3.00127458572
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
19.7319965363
2.59431242943
0.0
0.0
0.0
0.0
11.3581695557
0.0
0.0
45.6111793518
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
1.55515503883
0.0
0.0
1.68228709698
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
2.59581446648
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
9.05339717865
0.0
0.0
0.0
0.0
11.0281763077
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0
limit_output extension: Maximum message size of 10000 exceeded with 16331 characters

His Code

Batch 3

  • python ex3_batch.py $brand
  • runs this on each brand

In [1]:
import numpy as np
from vgg19 import VGG19
from resnet50 import ResNet50
from xception import Xception
from keras.preprocessing import image
from imagenet_utils import preprocess_input
from keras.models import Model
import itertools


Using TensorFlow backend.

In [2]:
def get_middle_layer(img_path):
	img = image.load_img(img_path, target_size=(224, 224))
	x = image.img_to_array(img)
	x = np.expand_dims(x, axis=0)
	x = preprocess_input(x)

	block4_pool_features = model.predict(x)
	flattened_list  = list(itertools.chain(*block4_pool_features.tolist()[0][0]))
	return flattened_list

def dot(K, L):
   if len(K) != len(L):
      return 0
   return sum(i[0] * i[1] for i in zip(K, L))

def similarity(item_1, item_2): 
	return dot(item_1, item_2) / np.sqrt(dot(item_1, item_1) * dot(item_2, item_2))

In [3]:
import os
import sys

base_model = ResNet50(include_top=False, weights='imagenet')
model = Model(input=base_model.input, output=base_model.get_layer('avg_pool').output)


resnet50.py:165: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(64, (7, 7), strides=(2, 2), name="conv1")`
  x = Convolution2D(64, 7, 7, subsample=(2, 2), name='conv1')(x)
resnet50.py:90: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(64, (1, 1), strides=(1, 1), name="res2a_branch2a")`
  name=conv_name_base + '2a')(input_tensor)
resnet50.py:95: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(64, (3, 3), padding="same", name="res2a_branch2b")`
  name=conv_name_base + '2b')(x)
resnet50.py:99: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (1, 1), name="res2a_branch2c")`
  x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x)
resnet50.py:103: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (1, 1), strides=(1, 1), name="res2a_branch1")`
  name=conv_name_base + '1')(input_tensor)
resnet50.py:106: UserWarning: The `merge` function is deprecated and will be removed after 08/2017. Use instead layers from `keras.layers.merge`, e.g. `add`, `concatenate`, etc.
  x = merge([x, shortcut], mode='sum')
/Users/chris/anaconda/envs/virtenv/lib/python2.7/site-packages/keras/legacy/layers.py:456: UserWarning: The `Merge` layer is deprecated and will be removed after 08/2017. Use instead layers from `keras.layers.merge`, e.g. `add`, `concatenate`, etc.
  name=name)
resnet50.py:51: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(64, (1, 1), name="res2b_branch2a")`
  x = Convolution2D(nb_filter1, 1, 1, name=conv_name_base + '2a')(input_tensor)
resnet50.py:56: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(64, (3, 3), padding="same", name="res2b_branch2b")`
  border_mode='same', name=conv_name_base + '2b')(x)
resnet50.py:60: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (1, 1), name="res2b_branch2c")`
  x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x)
resnet50.py:63: UserWarning: The `merge` function is deprecated and will be removed after 08/2017. Use instead layers from `keras.layers.merge`, e.g. `add`, `concatenate`, etc.
  x = merge([x, input_tensor], mode='sum')
resnet50.py:51: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(64, (1, 1), name="res2c_branch2a")`
  x = Convolution2D(nb_filter1, 1, 1, name=conv_name_base + '2a')(input_tensor)
resnet50.py:56: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(64, (3, 3), padding="same", name="res2c_branch2b")`
  border_mode='same', name=conv_name_base + '2b')(x)
resnet50.py:60: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (1, 1), name="res2c_branch2c")`
  x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x)
resnet50.py:90: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(128, (1, 1), strides=(2, 2), name="res3a_branch2a")`
  name=conv_name_base + '2a')(input_tensor)
resnet50.py:95: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(128, (3, 3), padding="same", name="res3a_branch2b")`
  name=conv_name_base + '2b')(x)
resnet50.py:99: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(512, (1, 1), name="res3a_branch2c")`
  x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x)
resnet50.py:103: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(512, (1, 1), strides=(2, 2), name="res3a_branch1")`
  name=conv_name_base + '1')(input_tensor)
resnet50.py:51: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(128, (1, 1), name="res3b_branch2a")`
  x = Convolution2D(nb_filter1, 1, 1, name=conv_name_base + '2a')(input_tensor)
resnet50.py:56: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(128, (3, 3), padding="same", name="res3b_branch2b")`
  border_mode='same', name=conv_name_base + '2b')(x)
resnet50.py:60: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(512, (1, 1), name="res3b_branch2c")`
  x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x)
resnet50.py:51: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(128, (1, 1), name="res3c_branch2a")`
  x = Convolution2D(nb_filter1, 1, 1, name=conv_name_base + '2a')(input_tensor)
resnet50.py:56: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(128, (3, 3), padding="same", name="res3c_branch2b")`
  border_mode='same', name=conv_name_base + '2b')(x)
resnet50.py:60: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(512, (1, 1), name="res3c_branch2c")`
  x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x)
resnet50.py:51: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(128, (1, 1), name="res3d_branch2a")`
  x = Convolution2D(nb_filter1, 1, 1, name=conv_name_base + '2a')(input_tensor)
resnet50.py:56: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(128, (3, 3), padding="same", name="res3d_branch2b")`
  border_mode='same', name=conv_name_base + '2b')(x)
resnet50.py:60: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(512, (1, 1), name="res3d_branch2c")`
  x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x)
resnet50.py:90: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (1, 1), strides=(2, 2), name="res4a_branch2a")`
  name=conv_name_base + '2a')(input_tensor)
resnet50.py:95: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (3, 3), padding="same", name="res4a_branch2b")`
  name=conv_name_base + '2b')(x)
resnet50.py:99: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(1024, (1, 1), name="res4a_branch2c")`
  x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x)
resnet50.py:103: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(1024, (1, 1), strides=(2, 2), name="res4a_branch1")`
  name=conv_name_base + '1')(input_tensor)
resnet50.py:51: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (1, 1), name="res4b_branch2a")`
  x = Convolution2D(nb_filter1, 1, 1, name=conv_name_base + '2a')(input_tensor)
resnet50.py:56: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (3, 3), padding="same", name="res4b_branch2b")`
  border_mode='same', name=conv_name_base + '2b')(x)
resnet50.py:60: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(1024, (1, 1), name="res4b_branch2c")`
  x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x)
resnet50.py:51: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (1, 1), name="res4c_branch2a")`
  x = Convolution2D(nb_filter1, 1, 1, name=conv_name_base + '2a')(input_tensor)
resnet50.py:56: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (3, 3), padding="same", name="res4c_branch2b")`
  border_mode='same', name=conv_name_base + '2b')(x)
resnet50.py:60: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(1024, (1, 1), name="res4c_branch2c")`
  x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x)
resnet50.py:51: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (1, 1), name="res4d_branch2a")`
  x = Convolution2D(nb_filter1, 1, 1, name=conv_name_base + '2a')(input_tensor)
resnet50.py:56: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (3, 3), padding="same", name="res4d_branch2b")`
  border_mode='same', name=conv_name_base + '2b')(x)
resnet50.py:60: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(1024, (1, 1), name="res4d_branch2c")`
  x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x)
resnet50.py:51: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (1, 1), name="res4e_branch2a")`
  x = Convolution2D(nb_filter1, 1, 1, name=conv_name_base + '2a')(input_tensor)
resnet50.py:56: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (3, 3), padding="same", name="res4e_branch2b")`
  border_mode='same', name=conv_name_base + '2b')(x)
resnet50.py:60: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(1024, (1, 1), name="res4e_branch2c")`
  x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x)
resnet50.py:51: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (1, 1), name="res4f_branch2a")`
  x = Convolution2D(nb_filter1, 1, 1, name=conv_name_base + '2a')(input_tensor)
resnet50.py:56: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (3, 3), padding="same", name="res4f_branch2b")`
  border_mode='same', name=conv_name_base + '2b')(x)
resnet50.py:60: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(1024, (1, 1), name="res4f_branch2c")`
  x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x)
resnet50.py:90: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(512, (1, 1), strides=(2, 2), name="res5a_branch2a")`
  name=conv_name_base + '2a')(input_tensor)
resnet50.py:95: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(512, (3, 3), padding="same", name="res5a_branch2b")`
  name=conv_name_base + '2b')(x)
resnet50.py:99: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(2048, (1, 1), name="res5a_branch2c")`
  x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x)
resnet50.py:103: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(2048, (1, 1), strides=(2, 2), name="res5a_branch1")`
  name=conv_name_base + '1')(input_tensor)
resnet50.py:51: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(512, (1, 1), name="res5b_branch2a")`
  x = Convolution2D(nb_filter1, 1, 1, name=conv_name_base + '2a')(input_tensor)
resnet50.py:56: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(512, (3, 3), padding="same", name="res5b_branch2b")`
  border_mode='same', name=conv_name_base + '2b')(x)
resnet50.py:60: UserWarning: Update your `Conv2D` call to the Keras 2
limit_output extension: Maximum message size of 10000 exceeded with 10700 characters

In [6]:
path = 'img/baiyi'

features = dict()
for filename in os.listdir(path): # loop through all images in the folder
	img_path = path + '/' + filename
	features[filename] = get_middle_layer(img_path) # get the features from the middle layer

In [12]:
len(features['Baiyixiuzi-B978N340-5.jpg'])


Out[12]:
2048

In [13]:
import itertools
similarities = {item: similarity(features[item[0]], features[item[1]]) for item in itertools.product(features,features)}
for key, item in similarities.items():
	print key[0] + '|' + key[1] + '|' + str(item)


Baiyixiuzi-B978N101-5.jpg|BAIYI-B1061N026-5.jpg|0.823859037591
BAI-B004-3N026-5.jpg|Baiyixiuzi-B942N313-5.jpg|0.648299622
Bai-B520N015-5.jpg|Baiyixiuzi-B942N313-5.jpg|0.840041769387
Baiyixiuzi-B942N313-5.jpg|Baiyixiuzi-B942N315-5.jpg|0.884754758629
B-B1088N409-5.jpg|BAI-B004-3N026-5.jpg|0.747560769344
Baiyixiuzi-B977N037-5.jpg|Bai-B520N015-5.jpg|0.764250298092
Baiyixiuzi-B977N037-5.jpg|BAIYI-B1057N382-5.jpg|0.679682253326
Bai-B520N015-5.jpg|Baiyixiuzi-B978N101-5.jpg|0.775114607128
BAIYI-B1008N299-5.jpg|Baiyixiuzi-B977N060-5.jpg|0.847416065421
BAIYI-B1061N026-5.jpg|BAI-B004-3N026-5.jpg|0.740372238027
B-A406001N004-5.jpg|BAI-B004-3N004-5.jpg|0.815767723995
Baiyixiuzi-B942N315-5.jpg|B-B1088N004-5.jpg|0.721332743827
BAIYI-B1010N356-5.jpg|B-A406001N004-5.jpg|0.704356704643
Baiyixiuzi-B942N313-5.jpg|Baiyixiuzi-B977N037-5.jpg|0.793354199302
Baiyixiuzi-B942N313-5.jpg|Baiyi-B987N026-5.jpg|0.780199081656
Baiyixiuzi-B977N060-5.jpg|BAI-B004-3N026-5.jpg|0.687669768634
B-A406001N004-5.jpg|Baiyixiuzi-B978N340-5.jpg|0.710318111887
Baiyixiuzi-B977N060-5.jpg|Baiyixiuzi-B977N060-5.jpg|1.0
Baiyixiuzi-B977N060-5.jpg|B-B1088N004-5.jpg|0.827904248606
Baiyixiuzi-B942N315-5.jpg|Bai-B520N026-5.jpg|0.726667188587
BAIYI-B1008N289-5.jpg|Bai-B520N026-5.jpg|0.688049297127
Baiyixiuzi-B978N101-5.jpg|BAIYI-B1010N356-5.jpg|0.832373368744
Bai-B520N015-5.jpg|Bai-B520N015-5.jpg|1.0
BAI-B004-3N026-5.jpg|B-A406001N004-5.jpg|0.696696023748
BAIYI-B1008N289-5.jpg|BAIYI-B1057N383-5.jpg|0.608454572057
BAIYI-B1008N289-5.jpg|BAIYI-B1061N026-5.jpg|0.725438138158
BAIYI-B1010N356-5.jpg|B-B1088N004-5.jpg|0.711266415885
Baiyixiuzi-B978N340-5.jpg|BAIYI-B1010N356-5.jpg|0.904044084477
Baiyi-B987N026-5.jpg|Bai-B520N015-5.jpg|0.797916906889
BAI-B004-3N004-5.jpg|Bai-B520N026-5.jpg|0.665983898918
Bai-B520N015-5.jpg|Baiyixiuzi-B977N060-5.jpg|0.845312214546
BAIYI-B1008N289-5.jpg|Baiyixiuzi-B977N037-5.jpg|0.804804138518
Baiyixiuzi-B977N037-5.jpg|Baiyixiuzi-B977N037-5.jpg|1.0
Baiyixiuzi-B977N037-5.jpg|Baiyixiuzi-B978N340-5.jpg|0.771421684677
BAI-B004-3N026-5.jpg|B-B1088N409-5.jpg|0.747560769344
Baiyixiuzi-B978N340-5.jpg|Baiyi-B987N026-5.jpg|0.931545608087
Baiyi-B987N026-5.jpg|Baiyixiuzi-B942N313-5.jpg|0.780199081656
BAIYI-B1010N356-5.jpg|BAIYI-B1008N289-5.jpg|0.770070457719
BAIYI-B1061N026-5.jpg|BAIYI-B1057N382-5.jpg|0.753455225119
Bai-B520N026-5.jpg|BAIYI-B1057N382-5.jpg|0.706461539837
Baiyixiuzi-B977N060-5.jpg|BAI-B004-3N004-5.jpg|0.819102792835
Baiyixiuzi-B942N315-5.jpg|Baiyixiuzi-B977N060-5.jpg|0.820689444499
Bai-B520N026-5.jpg|BAIYI-B1008N299-5.jpg|0.74185591254
Baiyixiuzi-B977N037-5.jpg|Bai-B520N026-5.jpg|0.666188596062
Bai-B520N026-5.jpg|B-A406001N004-5.jpg|0.736383170797
Baiyi-B987N026-5.jpg|Baiyixiuzi-B977N060-5.jpg|0.832830165789
BAIYI-B1057N383-5.jpg|B-B1088N004-5.jpg|0.548759277031
BAIYI-B1008N299-5.jpg|BAIYI-B1057N382-5.jpg|0.774228219652
Baiyixiuzi-B942N315-5.jpg|Bai-B520N015-5.jpg|0.79272069888
Bai-B520N026-5.jpg|BAIYI-B1061N026-5.jpg|0.812733420834
Baiyixiuzi-B978N340-5.jpg|Baiyixiuzi-B977N060-5.jpg|0.8489011451
Bai-B520N026-5.jpg|Baiyixiuzi-B977N060-5.jpg|0.7066017619
BAI-B004-3N026-5.jpg|BAI-B004-3N026-5.jpg|1.0
B-B1088N409-5.jpg|B-A406001N004-5.jpg|0.795839606089
Bai-B520N026-5.jpg|BAI-B004-3N026-5.jpg|0.726550082591
BAIYI-B1061N026-5.jpg|Baiyixiuzi-B978N101-5.jpg|0.823859037591
Baiyixiuzi-B978N340-5.jpg|BAIYI-B1061N026-5.jpg|0.848438889766
Baiyixiuzi-B977N037-5.jpg|Baiyixiuzi-B978N101-5.jpg|0.741367432561
Baiyixiuzi-B942N315-5.jpg|BAIYI-B1010N356-5.jpg|0.801104051108
B-B1088N409-5.jpg|Bai-B520N026-5.jpg|0.737943737512
Baiyixiuzi-B978N340-5.jpg|B-A406001N004-5.jpg|0.710318111887
BAIYI-B1057N382-5.jpg|Baiyixiuzi-B977N060-5.jpg|0.733453719732
BAIYI-B1061N026-5.jpg|Bai-B520N015-5.jpg|0.759025349329
Baiyixiuzi-B977N060-5.jpg|Baiyixiuzi-B978N101-5.jpg|0.796620263449
Baiyixiuzi-B942N313-5.jpg|Baiyixiuzi-B978N101-5.jpg|0.775181665223
BAIYI-B1010N356-5.jpg|Baiyixiuzi-B978N101-5.jpg|0.832373368744
BAIYI-B1008N289-5.jpg|B-B1088N004-5.jpg|0.806156137437
Bai-B520N026-5.jpg|Baiyixiuzi-B978N340-5.jpg|0.769888933747
BAIYI-B1057N382-5.jpg|BAIYI-B1057N382-5.jpg|1.0
BAI-B004-3N026-5.jpg|Baiyixiuzi-B978N340-5.jpg|0.763876809833
B-B1088N409-5.jpg|B-B1088N409-5.jpg|1.0
Baiyixiuzi-B977N060-5.jpg|Baiyixiuzi-B942N313-5.jpg|0.854384260032
BAIYI-B1061N026-5.jpg|BAIYI-B1057N383-5.jpg|0.747820257732
Baiyixiuzi-B942N315-5.jpg|BAI-B004-3N026-5.jpg|0.688141506879
B-B1088N409-5.jpg|BAIYI-B1057N383-5.jpg|0.612468688138
Baiyixiuzi-B977N037-5.jpg|BAIYI-B1008N299-5.jpg|0.800542029202
Bai-B520N026-5.jpg|Bai-B520N026-5.jpg|1.0
BAI-B004-3N026-5.jpg|BAIYI-B1008N289-5.jpg|0.662915792771
Baiyixiuzi-B977N060-5.jpg|BAIYI-B1057N382-5.jpg|0.733453719732
B-B1088N004-5.jpg|Bai-B520N015-5.jpg|0.808629376793
BAIYI-B1061N026-5.jpg|BAI-B004-3N004-5.jpg|0.678956296071
Baiyixiuzi-B942N315-5.jpg|BAIYI-B1061N026-5.jpg|0.777592388673
Baiyixiuzi-B977N060-5.jpg|BAIYI-B1008N299-5.jpg|0.847416065421
B-B1088N409-5.jpg|BAIYI-B1057N382-5.jpg|0.706088220865
Baiyixiuzi-B942N313-5.jpg|BAIYI-B1057N382-5.jpg|0.759389771218
Baiyixiuzi-B977N037-5.jpg|BAIYI-B1061N026-5.jpg|0.699824948945
B-A406001N004-5.jpg|Baiyixiuzi-B977N037-5.jpg|0.679109338937
BAIYI-B1057N383-5.jpg|Bai-B520N015-5.jpg|0.62904095986
BAIYI-B1057N383-5.jpg|Baiyi-B987N026-5.jpg|0.743810490198
BAI-B004-3N004-5.jpg|BAIYI-B1057N383-5.jpg|0.553483090621
Baiyixiuzi-B977N037-5.jpg|Baiyixiuzi-B977N060-5.jpg|0.890628401647
BAIYI-B1061N026-5.jpg|Baiyixiuzi-B977N060-5.jpg|0.756312042942
BAIYI-B1010N356-5.jpg|BAIYI-B1061N026-5.jpg|0.909476844611
Baiyixiuzi-B942N313-5.jpg|Bai-B520N026-5.jpg|0.70924871593
Baiyixiuzi-B977N037-5.jpg|BAI-B004-3N026-5.jpg|0.639824934
BAIYI-B1057N382-5.jpg|BAIYI-B1008N289-5.jpg|0.752589883715
B-B1088N004-5.jpg|Baiyi-B987N026-5.jpg|0.712933968595
Baiyi-B987N026-5.jpg|BAIYI-B1010N356-5.jpg|0.894313087607
BAIYI-B1057N382-5.jpg|Baiyixiuzi-B978N340-5.jpg|0.76086247692
BAIYI-B1057N382-5.jpg|Baiyixiuzi-B977N037-5.jpg|0.679682253326
BAIYI-B1057N383-5.jpg|BAIYI-B1010N356-5.jpg|0.731754530437
BAI-B004-3N004-5.jpg|B-B1088N409-5.jpg|0.851898083413
Baiyixiuzi-B978N101-5.jpg|Baiyixiuzi-B942N315-5.jpg|0.837940845975
BAIYI-B1010N356-5.jpg|BAI-B004-3N026-5.jpg|0.759525715861
B-B1088N004-5.jpg|BAIYI-B1008N289-5.jpg|0.806156137437
BAIYI-B1057N383-5.jpg|Baiyixiuzi-B942N315-5.jpg|0.704030634438
Bai-B520N015-5.jpg|BAIYI-B1057N382-5.jpg|0.718161851153
BAIYI-B1008N289-5.jpg|Baiyixiuzi-B978N340-5.jpg|0.814226934328
BAIYI-B1008N299-5.jpg|Baiyixiuzi-B942N313-5.jpg|0.868171967632
BAIYI-B1057N382-5.jpg|BAIYI-B1057N383-5.jpg|0.872775103019
Baiyixiuzi-B977N060-5.jpg|BAIYI-B1057N383-5.jpg|0.632118636805
B-B1088N004-5.jpg|Baiyixiuzi-B942N313-5.jpg|0.765187087395
B-B1088N004-5.jpg|Baiyixiuzi-B942N315-5.jpg|0.721332743827
BAI-B004-3N026-5.jpg|BAIYI-B1061N026-5.jpg|0.740372238027
B-A406001N004-5.jpg|B-B1088N004-5.jpg|0.8105609047
BAIYI-B1010N356-5.jpg|Baiyixiuzi-B942N313-5.jpg|0.779126715008
BAIYI-B1008N289-5.jpg|Baiyixiuzi-B978N101-5.jpg|0.744243511382
Baiyixiuzi-B942N315-5.jpg|Baiyixiuzi-B978N101-5.jpg|0.837940845975
BAI-B004-3N004-5.jpg|Baiyixiuzi-B977N037-5.jpg|0.78241909477
BAIYI-B1008N299-5.jpg|BAI-B004-3N026-5.jpg|0.660562257246
B-A406001N004-5.jpg|BAI-B004-3N026-5.jpg|0.696696023748
BAIYI-B1061N026-5.jpg|BAIYI-B1008N299-5.jpg|0.778695488056
B-B1088N004-5.jpg|B-B1088N004-5.jpg|1.0
BAIYI-B1057N383-5.jpg|BAI-B004-3N026-5.jpg|0.579853452137
BAI-B004-3N004-5.jpg|BAIYI-B1057N382-5.jpg|0.646787719756
Baiyixiuzi-B978N101-5.jpg|BAIYI-B1057N383-5.jpg|0.69670247243
B-A406001N004-5.jpg|BAIYI-B1057N383-5.jpg|0.562087954992
B-B1088N004-5.jpg|BAIYI-B1061N026-5.jpg|0.658244978694
Baiyixiuzi-B978N101-5.jpg|Baiyixiuzi-B977N060-5.jpg|0.796620263449
BAIYI-B1061N026-5.jpg|B-B1088N004-5.jpg|0.658244978694
BAIYI-B1008N299-5.jpg|BAIYI-B1061N026-5.jpg|0.778695488056
B-B1088N004-5.jpg|BAIYI-B1008N299-5.jpg|0.733652231732
BAIYI-B1008N299-5.jpg|B-B1088N409-5.jpg|0.768598338227
BAIYI-B1008N289-5.jpg|B-B1088N409-5.jpg|0.830753464748
BAIYI-B1010N356-5.jpg|Baiyixiuzi-B978N340-5.jpg|0.904044084477
BAIYI-B1057N383-5.jpg|BAIYI-B1061N026-5.jpg|0.747820257732
BAI-B004-3N026-5.jpg|B-B1088N004-5.jpg|0.689875006908
Bai-B520N015-5.jpg|BAI-B004-3N004-5.jpg|0.825117295328
BAIYI-B1057N382-5.jpg|BAI-B004-3N026-5.jpg|0.638524709034
BAIYI-B1061N026-5.jpg|Baiyixiuzi-B942N315-5.jpg|0.777592388673
Baiyixiuzi-B978N101-5.jpg|B-A406001N004-5.jpg|0.662527583556
Baiyixiuzi-B942N315-5.jpg|Baiyi-B987N026-5.jpg|0.827420752934
BAIYI-B1010N356-5.jpg|BAIYI-B1057N383-5.jpg|0.731754530437
B-B1088N409-5.jpg|Baiyixiuzi-B942N315-5.jpg|0.770751820892
Baiyi-B987N026-5.jpg|Bai-B520N026-5.jpg|0.808050437037
Bai-B520N015-5.jpg|Baiyixiuzi-B978N340-5.jpg|0.82158212548
BAI-B004-3N026-5.jpg|BAIYI-B1010N356-5.jpg|0.759525715861
BAI-B004-3N004-5.jpg|Baiyixiuzi-B978N101-5.jpg|0.687134636335
BAIYI-B1008N289-5.jpg|BAI-B004-3N004-5.jpg|0.768275308875
B-A406001N004-5.jpg|Bai-B520N015-5.jpg|0.825139504726
B-B1088N409-5.jpg|BAIYI-B1008N299-5.jpg|0.768598338227
Baiyixiuzi-B942N315-5.jpg|Baiyixiuzi-B942N315-5.jpg|1.0
Baiyixiuzi-B978N340-5.jpg|Bai-B520N015-5.jpg|0.82158212548
B-B1088N409-5.jpg|Baiyi-B987N026-5.jpg|0.82228192994
BAI-B004-3N026-5.jpg|Bai-B520N015-5.jpg|0.700566877629
Baiyixiuzi-B978N340-5.jpg|Baiyixiuzi-B942N313-5.jpg|0.82320922706
Bai-B520N026-5.jpg|BAI-B004-3N004-5.jpg|0.665983898918
BAIYI-B1008N289-5.jpg|B-A406001N004-5.jpg|0.676637610818
BAI-B004-3N004-5.jpg|BAIYI-B1008N289-5.jpg|0.768275308875
BAIYI-B1008N299-5.jpg|Baiyixiuzi-B978N101-5.jpg|0.822831042879
BAIYI-B1061N026-5.jpg|BAIYI-B1061N026-5.jpg|1.0
B-A406001N004-5.jpg|Baiyixiuzi-B977N060-5.jpg|0.734086264954
Baiyixiuzi-B978N101-5.jpg|Baiyixiuzi-B942N313-5.jpg|0.775181665223
BAI-B004-3N026-5.jpg|Baiyixiuzi-B977N060-5.jpg|0.687669768634
BAIYI-B1057N382-5.jpg|Bai-B520N015-5.jpg|0.718161851153
Baiyixiuzi-B977N060-5.jpg|BAIYI-B1061N026-5.jpg|0.756312042942
B-B1088N409-5.jpg|Baiyixiuzi-B942N313-5.jpg|0.788676607227
BAIYI-B1057N382-5.jpg|Baiyixiuzi-B942N315-5.jpg|0.774222214365
BAI-B004-3N004-5.jpg|BAI-B004-3N004-5.jpg|1.0
Baiyixiuzi-B977N060-5.jpg|BAIYI-B1008N289-5.jpg|0.869941878252
BA
limit_output extension: Maximum message size of 10000 exceeded with 23522 characters

In [16]:
similarities


Out[16]:
{('B-A406001N004-5.jpg', 'B-A406001N004-5.jpg'): 1.0,
 ('B-A406001N004-5.jpg', 'B-B1088N004-5.jpg'): 0.81056090469981612,
 ('B-A406001N004-5.jpg', 'B-B1088N409-5.jpg'): 0.79583960608883408,
 ('B-A406001N004-5.jpg', 'BAI-B004-3N004-5.jpg'): 0.81576772399522668,
 ('B-A406001N004-5.jpg', 'BAI-B004-3N026-5.jpg'): 0.69669602374807649,
 ('B-A406001N004-5.jpg', 'BAIYI-B1008N289-5.jpg'): 0.67663761081822882,
 ('B-A406001N004-5.jpg', 'BAIYI-B1008N299-5.jpg'): 0.68029326927141098,
 ('B-A406001N004-5.jpg', 'BAIYI-B1010N356-5.jpg'): 0.70435670464269862,
 ('B-A406001N004-5.jpg', 'BAIYI-B1057N382-5.jpg'): 0.60715653253139457,
 ('B-A406001N004-5.jpg', 'BAIYI-B1057N383-5.jpg'): 0.56208795499215936,
 ('B-A406001N004-5.jpg', 'BAIYI-B1061N026-5.jpg'): 0.68490847413743161,
 ('B-A406001N004-5.jpg', 'Bai-B520N015-5.jpg'): 0.82513950472577502,
 ('B-A406001N004-5.jpg', 'Bai-B520N026-5.jpg'): 0.73638317079718996,
 ('B-A406001N004-5.jpg', 'Baiyi-B987N026-5.jpg'): 0.69680544143997858,
 ('B-A406001N004-5.jpg', 'Baiyixiuzi-B942N313-5.jpg'): 0.69985185372275438,
 ('B-A406001N004-5.jpg', 'Baiyixiuzi-B942N315-5.jpg'): 0.6781243368664055,
 ('B-A406001N004-5.jpg', 'Baiyixiuzi-B977N037-5.jpg'): 0.67910933893711745,
 ('B-A406001N004-5.jpg', 'Baiyixiuzi-B977N060-5.jpg'): 0.73408626495379525,
 ('B-A406001N004-5.jpg', 'Baiyixiuzi-B978N101-5.jpg'): 0.66252758355580921,
 ('B-A406001N004-5.jpg', 'Baiyixiuzi-B978N340-5.jpg'): 0.71031811188672855,
 ('B-B1088N004-5.jpg', 'B-A406001N004-5.jpg'): 0.81056090469981612,
 ('B-B1088N004-5.jpg', 'B-B1088N004-5.jpg'): 1.0,
 ('B-B1088N004-5.jpg', 'B-B1088N409-5.jpg'): 0.90888858094471348,
 ('B-B1088N004-5.jpg', 'BAI-B004-3N004-5.jpg'): 0.86398128700449939,
 ('B-B1088N004-5.jpg', 'BAI-B004-3N026-5.jpg'): 0.68987500690767845,
 ('B-B1088N004-5.jpg', 'BAIYI-B1008N289-5.jpg'): 0.80615613743650716,
 ('B-B1088N004-5.jpg', 'BAIYI-B1008N299-5.jpg'): 0.73365223173206828,
 ('B-B1088N004-5.jpg', 'BAIYI-B1010N356-5.jpg'): 0.71126641588518413,
 ('B-B1088N004-5.jpg', 'BAIYI-B1057N382-5.jpg'): 0.64736624890443195,
 ('B-B1088N004-5.jpg', 'BAIYI-B1057N383-5.jpg'): 0.54875927703081084,
 ('B-B1088N004-5.jpg', 'BAIYI-B1061N026-5.jpg'): 0.65824497869441168,
 ('B-B1088N004-5.jpg', 'Bai-B520N015-5.jpg'): 0.80862937679279334,
 ('B-B1088N004-5.jpg', 'Bai-B520N026-5.jpg'): 0.67156587864754724,
 ('B-B1088N004-5.jpg', 'Baiyi-B987N026-5.jpg'): 0.71293396859502423,
 ('B-B1088N004-5.jpg', 'Baiyixiuzi-B942N313-5.jpg'): 0.76518708739484043,
 ('B-B1088N004-5.jpg', 'Baiyixiuzi-B942N315-5.jpg'): 0.72133274382694401,
 ('B-B1088N004-5.jpg', 'Baiyixiuzi-B977N037-5.jpg'): 0.78857350444781493,
 ('B-B1088N004-5.jpg', 'Baiyixiuzi-B977N060-5.jpg'): 0.82790424860648204,
 ('B-B1088N004-5.jpg', 'Baiyixiuzi-B978N101-5.jpg'): 0.65643844375221239,
 ('B-B1088N004-5.jpg', 'Baiyixiuzi-B978N340-5.jpg'): 0.74277291031508708,
 ('B-B1088N409-5.jpg', 'B-A406001N004-5.jpg'): 0.79583960608883408,
 ('B-B1088N409-5.jpg', 'B-B1088N004-5.jpg'): 0.90888858094471348,
 ('B-B1088N409-5.jpg', 'B-B1088N409-5.jpg'): 1.0,
 ('B-B1088N409-5.jpg', 'BAI-B004-3N004-5.jpg'): 0.85189808341338735,
 ('B-B1088N409-5.jpg', 'BAI-B004-3N026-5.jpg'): 0.74756076934393778,
 ('B-B1088N409-5.jpg', 'BAIYI-B1008N289-5.jpg'): 0.83075346474788214,
 ('B-B1088N409-5.jpg', 'BAIYI-B1008N299-5.jpg'): 0.76859833822738488,
 ('B-B1088N409-5.jpg', 'BAIYI-B1010N356-5.jpg'): 0.79941801683259417,
 ('B-B1088N409-5.jpg', 'BAIYI-B1057N382-5.jpg'): 0.70608822086457046,
 ('B-B1088N409-5.jpg', 'BAIYI-B1057N383-5.jpg'): 0.6124686881383985,
 ('B-B1088N409-5.jpg', 'BAIYI-B1061N026-5.jpg'): 0.74114377347980764,
 ('B-B1088N409-5.jpg', 'Bai-B520N015-5.jpg'): 0.85186863482538078,
 ('B-B1088N409-5.jpg', 'Bai-B520N026-5.jpg'): 0.73794373751238196,
 ('B-B1088N409-5.jpg', 'Baiyi-B987N026-5.jpg'): 0.82228192993999072,
 ('B-B1088N409-5.jpg', 'Baiyixiuzi-B942N313-5.jpg'): 0.7886766072270851,
 ('B-B1088N409-5.jpg', 'Baiyixiuzi-B942N315-5.jpg'): 0.77075182089240857,
 ('B-B1088N409-5.jpg', 'Baiyixiuzi-B977N037-5.jpg'): 0.795838539240733,
 ('B-B1088N409-5.jpg', 'Baiyixiuzi-B977N060-5.jpg'): 0.85747065946674916,
 ('B-B1088N409-5.jpg', 'Baiyixiuzi-B978N101-5.jpg'): 0.75250029370640692,
 ('B-B1088N409-5.jpg', 'Baiyixiuzi-B978N340-5.jpg'): 0.83627033540504414,
 ('BAI-B004-3N004-5.jpg', 'B-A406001N004-5.jpg'): 0.81576772399522668,
 ('BAI-B004-3N004-5.jpg', 'B-B1088N004-5.jpg'): 0.86398128700449939,
 ('BAI-B004-3N004-5.jpg', 'B-B1088N409-5.jpg'): 0.85189808341338735,
 ('BAI-B004-3N004-5.jpg', 'BAI-B004-3N004-5.jpg'): 1.0,
 ('BAI-B004-3N004-5.jpg', 'BAI-B004-3N026-5.jpg'): 0.74364699607893148,
 ('BAI-B004-3N004-5.jpg', 'BAIYI-B1008N289-5.jpg'): 0.76827530887469198,
 ('BAI-B004-3N004-5.jpg', 'BAIYI-B1008N299-5.jpg'): 0.73201187404369872,
 ('BAI-B004-3N004-5.jpg', 'BAIYI-B1010N356-5.jpg'): 0.7450936750820637,
 ('BAI-B004-3N004-5.jpg', 'BAIYI-B1057N382-5.jpg'): 0.64678771975603366,
 ('BAI-B004-3N004-5.jpg', 'BAIYI-B1057N383-5.jpg'): 0.55348309062112111,
 ('BAI-B004-3N004-5.jpg', 'BAIYI-B1061N026-5.jpg'): 0.6789562960710267,
 ('BAI-B004-3N004-5.jpg', 'Bai-B520N015-5.jpg'): 0.82511729532764944,
 ('BAI-B004-3N004-5.jpg', 'Bai-B520N026-5.jpg'): 0.66598389891751053,
 ('BAI-B004-3N004-5.jpg', 'Baiyi-B987N026-5.jpg'): 0.71592749808871647,
 ('BAI-B004-3N004-5.jpg', 'Baiyixiuzi-B942N313-5.jpg'): 0.78903487752860824,
 ('BAI-B004-3N004-5.jpg', 'Baiyixiuzi-B942N315-5.jpg'): 0.75603285464443148,
 ('BAI-B004-3N004-5.jpg', 'Baiyixiuzi-B977N037-5.jpg'): 0.78241909477049054,
 ('BAI-B004-3N004-5.jpg', 'Baiyixiuzi-B977N060-5.jpg'): 0.81910279283452214,
 ('BAI-B004-3N004-5.jpg', 'Baiyixiuzi-B978N101-5.jpg'): 0.68713463633485605,
 ('BAI-B004-3N004-5.jpg', 'Baiyixiuzi-B978N340-5.jpg'): 0.76220620050446874,
 ('BAI-B004-3N026-5.jpg', 'B-A406001N004-5.jpg'): 0.69669602374807649,
 ('BAI-B004-3N026-5.jpg', 'B-B1088N004-5.jpg'): 0.68987500690767845,
 ('BAI-B004-3N026-5.jpg', 'B-B1088N409-5.jpg'): 0.74756076934393778,
 ('BAI-B004-3N026-5.jpg', 'BAI-B004-3N004-5.jpg'): 0.74364699607893148,
 ('BAI-B004-3N026-5.jpg', 'BAI-B004-3N026-5.jpg'): 1.0,
 ('BAI-B004-3N026-5.jpg', 'BAIYI-B1008N289-5.jpg'): 0.66291579277051216,
 ('BAI-B004-3N026-5.jpg', 'BAIYI-B1008N299-5.jpg'): 0.66056225724582618,
 ('BAI-B004-3N026-5.jpg', 'BAIYI-B1010N356-5.jpg'): 0.75952571586077355,
 ('BAI-B004-3N026-5.jpg', 'BAIYI-B1057N382-5.jpg'): 0.63852470903432268,
 ('BAI-B004-3N026-5.jpg', 'BAIYI-B1057N383-5.jpg'): 0.57985345213737582,
 ('BAI-B004-3N026-5.jpg', 'BAIYI-B1061N026-5.jpg'): 0.7403722380273533,
 ('BAI-B004-3N026-5.jpg', 'Bai-B520N015-5.jpg'): 0.70056687762915304,
 ('BAI-B004-3N026-5.jpg', 'Bai-B520N026-5.jpg'): 0.72655008259067366,
 ('BAI-B004-3N026-5.jpg', 'Baiyi-B987N026-5.jpg'): 0.76712791211269427,
 ('BAI-B004-3N026-5.jpg', 'Baiyixiuzi-B942N313-5.jpg'): 0.64829962199964353,
 ('BAI-B004-3N026-5.jpg', 'Baiyixiuzi-B942N315-5.jpg'): 0.68814150687882514,
 ('BAI-B004-3N026-5.jpg', 'Baiyixiuzi-B977N037-5.jpg'): 0.63982493400048923,
 ('BAI-B004-3N026-5.jpg', 'Baiyixiuzi-B977N060-5.jpg'): 0.68766976863438345,
 ('BAI-B004-3N026-5.jpg', 'Baiyixiuzi-B978N101-5.jpg'): 0.69112467225093199,
 ('BAI-B004-3N026-5.jpg', 'Baiyixiuzi-B978N340-5.jpg'): 0.76387680983345185,
 ('BAIYI-B1008N289-5.jpg', 'B-A406001N004-5.jpg'): 0.67663761081822882,
 ('BAIYI-B1008N289-5.jpg', 'B-B1088N004-5.jpg'): 0.80615613743650716,
 ('BAIYI-B1008N289-5.jpg', 'B-B1088N409-5.jpg'): 0.83075346474788214,
 ('BAIYI-B1008N289-5.jpg', 'BAI-B004-3N004-5.jpg'): 0.76827530887469198,
 ('BAIYI-B1008N289-5.jpg', 'BAI-B004-3N026-5.jpg'): 0.66291579277051216,
 ('BAIYI-B1008N289-5.jpg', 'BAIYI-B1008N289-5.jpg'): 1.0,
 ('BAIYI-B1008N289-5.jpg', 'BAIYI-B1008N299-5.jpg'): 0.84453435962753309,
 ('BAIYI-B1008N289-5.jpg', 'BAIYI-B1010N356-5.jpg'): 0.77007045771922811,
 ('BAIYI-B1008N289-5.jpg', 'BAIYI-B1057N382-5.jpg'): 0.75258988371498081,
 ('BAIYI-B1008N289-5.jpg', 'BAIYI-B1057N383-5.jpg'): 0.60845457205702091,
 ('BAIYI-B1008N289-5.jpg', 'BAIYI-B1061N026-5.jpg'): 0.72543813815815072,
 ('BAIYI-B1008N289-5.jpg', 'Bai-B520N015-5.jpg'): 0.84710592934518858,
 ('BAIYI-B1008N289-5.jpg', 'Bai-B520N026-5.jpg'): 0.68804929712664131,
 ('BAIYI-B1008N289-5.jpg', 'Baiyi-B987N026-5.jpg'): 0.78525739853730547,
 ('BAIYI-B1008N289-5.jpg', 'Baiyixiuzi-B942N313-5.jpg'): 0.88676434244167524,
 ('BAIYI-B1008N289-5.jpg', 'Baiyixiuzi-B942N315-5.jpg'): 0.81142117729606378,
 ('BAIYI-B1008N289-5.jpg', 'Baiyixiuzi-B977N037-5.jpg'): 0.80480413851830068,
 ('BAIYI-B1008N289-5.jpg', 'Baiyixiuzi-B977N060-5.jpg'): 0.86994187825244906,
 ('BAIYI-B1008N289-5.jpg', 'Baiyixiuzi-B978N101-5.jpg'): 0.74424351138249123,
 ('BAIYI-B1008N289-5.jpg', 'Baiyixiuzi-B978N340-5.jpg'): 0.81422693432813198,
 ('BAIYI-B1008N299-5.jpg', 'B-A406001N004-5.jpg'): 0.68029326927141098,
 ('BAIYI-B1008N299-5.jpg', 'B-B1088N004-5.jpg'): 0.73365223173206828,
 ('BAIYI-B1008N299-5.jpg', 'B-B1088N409-5.jpg'): 0.76859833822738488,
 ('BAIYI-B1008N299-5.jpg', 'BAI-B004-3N004-5.jpg'): 0.73201187404369872,
 ('BAIYI-B1008N299-5.jpg', 'BAI-B004-3N026-5.jpg'): 0.66056225724582618,
 ('BAIYI-B1008N299-5.jpg', 'BAIYI-B1008N289-5.jpg'): 0.84453435962753309,
 ('BAIYI-B1008N299-5.jpg', 'BAIYI-B1008N299-5.jpg'): 1.0,
 ('BAIYI-B1008N299-5.jpg', 'BAIYI-B1010N356-5.jpg'): 0.77945698858977797,
 ('BAIYI-B1008N299-5.jpg', 'BAIYI-B1057N382-5.jpg'): 0.77422821965206001,
 ('BAIYI-B1008N299-5.jpg', 'BAIYI-B1057N383-5.jpg'): 0.67737061813629262,
 ('BAIYI-B1008N299-5.jpg', 'BAIYI-B1061N026-5.jpg'): 0.7786954880564807,
 ('BAIYI-B1008N299-5.jpg', 'Bai-B520N015-5.jpg'): 0.80682861147649687,
 ('BAIYI-B1008N299-5.jpg', 'Bai-B520N026-5.jpg'): 0.74185591253995231,
 ('BAIYI-B1008N299-5.jpg', 'Baiyi-B987N026-5.jpg'): 0.83290380862283886,
 ('BAIYI-B1008N299-5.jpg', 'Baiyixiuzi-B942N313-5.jpg'): 0.86817196763197613,
 ('BAIYI-B1008N299-5.jpg', 'Baiyixiuzi-B942N315-5.jpg'): 0.90288139657900512,
 ('BAIYI-B1008N299-5.jpg', 'Baiyixiuzi-B977N037-5.jpg'): 0.80054202920247552,
 ('BAIYI-B1008N299-5.jpg', 'Baiyixiuzi-B977N060-5.jpg'): 0.84741606542119319,
 ('BAIYI-B1008N299-5.jpg', 'Baiyixiuzi-B978N101-5.jpg'): 0.82283104287857389,
 ('BAIYI-B1008N299-5.jpg', 'Baiyixiuzi-B978N
limit_output extension: Maximum message size of 10000 exceeded with 29495 characters

Creating User Vecs


In [130]:
import math
import numpy as np
import pandas as pd
import pickle
import sys
sys.path.append('4.personalization/')
import utils.kmeans as kmeans
from collections import Counter

In [125]:
def average(lists):
    #Tracer()()
    return [np.mean(i) for i in zip(*[l for l in lists])]

In [139]:
def cluster(lists, model):
    #Tracer()()
    user_cluster = kmeans.predict(np.array([l for l in lists]), model)
    user_vec = [0] * model.n_clusters
    for i in user_cluster: user_vec[i] += 1
    return [elem / float(sum(user_vec)) for elem in user_vec]

In [89]:
user_log = pd.read_pickle('4.personalization/data/viewlist_imagef.pkl')

In [124]:
user_vec = user_log.groupby(['user_id', 'dt'])['features'].apply(lambda x: average(x))


/Users/chris/anaconda/envs/virtenv/lib/python2.7/site-packages/ipykernel_launcher.py:2: DeprecationWarning: `Tracer` is deprecated since version 5.1, directly use `IPython.core.debugger.Pdb.set_trace()`
  
> <ipython-input-123-60a1ef84013a>(3)average()
      1 def average(lists):
      2     Tracer()()
----> 3     return [np.mean(i) for i in zip(*[l for l in lists])]

ipdb> list
      1 def average(lists):
      2     Tracer()()
----> 3     return [np.mean(i) for i in zip(*[l for l in lists])]

ipdb> lists
58589    [0.387, 1.751, 0.032, 0.452, 0.087, 0.361, 1.3...
79516    [0.33, 0.578, 0.013, 0.635, 0.361, 0.026, 0.07...
84702    [0.729, 0.606, 0.021, 2.631, 0.061, 0.292, 1.1...
Name: (17940, 20170308), dtype: object
ipdb> type(lists)
<class 'pandas.core.series.Series'>
ipdb> q
Exiting Debugger.

In [94]:
user_log.groupby(['user_id', 'dt'])


Out[94]:
<pandas.core.groupby.DataFrameGroupBy object at 0x129a0f850>

In [100]:
user_log[0:100].groupby(['user_id', 'dt'])['features'].apply(lambda x: x)


Out[100]:
<pandas.core.groupby.SeriesGroupBy object at 0x12a849890>

In [102]:
f = lambda y: y**2
f(7)


Out[102]:
49

In [119]:
#user_log[0:100].groupby(['user_id', 'dt'])['goods_no'].apply(lambda x: x)

In [132]:
model_path='4.personalization/utils/model.pkl'
model = kmeans.load_model(model_path)


/Users/chris/anaconda/envs/virtenv/lib/python2.7/site-packages/sklearn/base.py:315: UserWarning: Trying to unpickle estimator KMeans from version pre-0.18 when using version 0.18.1. This might lead to breaking code or invalid results. Use at your own risk.
  UserWarning)

In [134]:
type(model)


Out[134]:
sklearn.cluster.k_means_.KMeans

In [137]:
model.cluster_centers_.shape


Out[137]:
(100, 2048)

In [140]:
user_vec = user_log.groupby(['user_id', 'dt'])['features'].apply(lambda x: cluster(x, model))

In [150]:
len(user_vec[0])


Out[150]:
100

Exploring the Data

  • requires the virt-env to be set-up WTF!

In [25]:
buylist = pd.read_pickle('4.personalization/data/buylist_imagef2.pkl')
buylist.head(20)


Out[25]:
user_id goods_no spu_id pkl_path features
0 17940 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
1 2259196 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
2 5163437 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
3 19899166 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
4 29046753 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
5 31107795 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
6 33715823 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
7 43685589 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
8 50368481 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
9 55679487 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
10 58656246 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
11 66464057 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
12 66582191 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
13 85013965 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
14 87656438 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
15 88707455 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
16 89980766 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
17 107310401 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
18 109065022 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...
19 112176989 S62X0006A121 3918489495497789461 /root/pkl/334/10012320/data.pkl [0.329701840878, 0.578402042389, 0.01264389045...

In [51]:
candidates = pd.read_pickle('4.personalization/data/candidates.pkl')
candidates.head()


Out[51]:
goods_no spu_id features
0 S62X0006A121 3918489495497789461 [0.329701840878, 0.578402042389, 0.01264389045...
46 S71R0003A28 33290489224151212 [0.0, 0.0892547890544, 0.00202232715674, 0.494...
120 S63K0003A7 310261851791720460 [0.737916231155, 0.934333741665, 0.0, 0.501327...
156 S63H0267A10 5142964296745125 [0.446703672409, 1.76493012905, 0.010568439960...
208 S63U0078A3 2609694530945034 [0.467104375362, 1.10197365284, 0.009207816794...
  • candiates are items

In [7]:
candidates_cluster = pd.read_pickle('4.personalization/data/candidates_cluster.pkl')
candidates_cluster.head()


Out[7]:
goods_no spu_id cluster
0 S62X0006A121 3918489495497789461 [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, ...
46 S71R0003A28 33290489224151212 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
120 S63K0003A7 310261851791720460 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, ...
156 S63H0267A10 5142964296745125 [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
208 S63U0078A3 2609694530945034 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...

In [8]:
user_vec_average = pd.read_pickle('4.personalization/data/user_vec_average.pkl')
user_vec_average.head()


Out[8]:
user_id dt features
0 17940 20170308 [0.482, 0.978333333333, 0.022, 1.23933333333, ...
1 193534 20170307 [0.24025, 0.326125, 0.094875, 0.69475, 0.37137...
2 205456 20170308 [0.263666666667, 0.508333333333, 0.00366666666...
3 251058 20170310 [0.302692307692, 0.617153846154, 0.04069230769...
4 307275 20170309 [0.2045, 0.557, 0.1135, 0.9615, 0.0985, 0.051,...
  • These features are from the images of the previous users. These are the average of the previous images viewed.

In [155]:
user_vec_average_no_pv = pd.read_pickle('4.personalization/data/user_vec_average_no_pv.pkl')
user_vec_average_no_pv.head()


Out[155]:
user_id dt features
0 17940 20170308 [0.482, 0.978333333333, 0.022, 1.23933333333, ...
1 193534 20170307 [0.3844, 0.4684, 0.1506, 0.8152, 0.2936, 0.108...
2 205456 20170308 [0.263666666667, 0.508333333333, 0.00366666666...
3 251058 20170310 [0.316727272727, 0.684818181818, 0.04390909090...
4 307275 20170309 [0.2045, 0.557, 0.1135, 0.9615, 0.0985, 0.051,...

In [152]:
user_vec_cluster = pd.read_pickle('4.personalization/data/user_vec_cluster.pkl')
user_vec_cluster.head()


Out[152]:
user_id dt features
0 17940 20170308 [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, ...
1 193534 20170307 [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.125, 0.0, 0.0...
2 205456 20170308 [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, ...
3 251058 20170310 [0.0769230769231, 0.153846153846, 0.0, 0.0, 0....
4 307275 20170309 [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, ...
  • These features are from the images of the previous users. These are clusters assigned to each image. In an algorithm later, it's easier to just compare similarities of items within the same cluster (rather than every pairwise image).

In [154]:
len(user_vec_cluster['features'][0])


Out[154]:
100

In [13]:
viewlist = pd.read_pickle('4.personalization/data/viewlist_imagef.pkl')


Out[13]:
user_id dt goods_no spu_id brand_store_sn formar14_pv pkl_path features
0 2081602 20170307 LA12351XBE 8377053158099693598 10010460 1 /root/pickle/334/10010460/data.pkl [0.05, 1.234, 0.0, 0.027, 0.321, 0.0, 0.149, 0...
1 2081602 20170307 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
2 26471171 20170313 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
3 93533432 20170310 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
4 94356672 20170307 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...

In [14]:
viewlist.head(100)


Out[14]:
user_id dt goods_no spu_id brand_store_sn formar14_pv pkl_path features
0 2081602 20170307 LA12351XBE 8377053158099693598 10010460 1 /root/pickle/334/10010460/data.pkl [0.05, 1.234, 0.0, 0.027, 0.321, 0.0, 0.149, 0...
1 2081602 20170307 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
2 26471171 20170313 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
3 93533432 20170310 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
4 94356672 20170307 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
5 94356672 20170307 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
6 94356672 20170307 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
7 94356672 20170307 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
8 127228744 20170307 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
9 190085911 20170311 LA11769CCW 7951181518336483573 10010460 2 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
10 190085911 20170311 LA11769CCW 7951181518336483573 10010460 2 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
11 197403915 20170309 LA11769CCW 7951181518336483573 10010460 2 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
12 232075039 20170310 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
13 2081602 20170307 LB14746QC8 8971246838881059027 10010460 1 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
14 25977414 20170310 LB14746QC8 8971246838881059027 10010460 4 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
15 25977414 20170310 LB14746QC8 8971246838881059027 10010460 1 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
16 126825162 20170308 LB14746QC8 8971246838881059027 10010460 1 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
17 190085911 20170311 LB14746QC8 8971246838881059027 10010460 2 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
18 213180245 20170307 LB14746QC8 8971246838881059027 10010460 1 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
19 216094334 20170307 LB14746QC8 8971246838881059027 10010460 1 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
20 2081602 20170307 LA10637QC9 8970965363904348381 10010460 3 /root/pickle/334/10010460/data.pkl [0.007, 1.391, 0.313, 0.13, 0.07, 0.0, 0.081, ...
21 18318014 20170308 LA10637QC9 8970965363904348381 10010460 1 /root/pickle/334/10010460/data.pkl [0.007, 1.391, 0.313, 0.13, 0.07, 0.0, 0.081, ...
22 20408504 20170307 LA10637QC9 8970965363904348381 10010460 3 /root/pickle/334/10010460/data.pkl [0.007, 1.391, 0.313, 0.13, 0.07, 0.0, 0.081, ...
23 25589014 20170308 LA10637QC9 8970965363904348381 10010460 1 /root/pickle/334/10010460/data.pkl [0.007, 1.391, 0.313, 0.13, 0.07, 0.0, 0.081, ...
24 25589014 20170308 LA10637QC9 8970965363904348381 10010460 1 /root/pickle/334/10010460/data.pkl [0.007, 1.391, 0.313, 0.13, 0.07, 0.0, 0.081, ...
25 25977414 20170310 LA10637QC9 8970965363904348381 10010460 3 /root/pickle/334/10010460/data.pkl [0.007, 1.391, 0.313, 0.13, 0.07, 0.0, 0.081, ...
26 25977414 20170310 LA10637QC9 8970965363904348381 10010460 2 /root/pickle/334/10010460/data.pkl [0.007, 1.391, 0.313, 0.13, 0.07, 0.0, 0.081, ...
27 31109177 20170310 LA10637QC9 8970965363904348381 10010460 1 /root/pickle/334/10010460/data.pkl [0.007, 1.391, 0.313, 0.13, 0.07, 0.0, 0.081, ...
28 39538069 20170308 LA10637QC9 8970965363904348381 10010460 1 /root/pickle/334/10010460/data.pkl [0.007, 1.391, 0.313, 0.13, 0.07, 0.0, 0.081, ...
29 44806033 20170309 LA10637QC9 8970965363904348381 10010460 5 /root/pickle/334/10010460/data.pkl [0.007, 1.391, 0.313, 0.13, 0.07, 0.0, 0.081, ...
... ... ... ... ... ... ... ... ...
70 234155659 20170310 LA10637QC9 8970965363904348381 10010460 4 /root/pickle/334/10010460
limit_output extension: Maximum message size of 10000 exceeded with 18882 characters

In [29]:
viewlist_exp = pd.read_pickle('4.personalization/data/viewlist_imagef_exp.pkl')


Out[29]:
user_id dt goods_no spu_id brand_store_sn formar14_pv pkl_path features
0 2081602 20170307 LA12351XBE 8377053158099693598 10010460 1 /root/pickle/334/10010460/data.pkl [0.05, 1.234, 0.0, 0.027, 0.321, 0.0, 0.149, 0...
1 2081602 20170307 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
2 26471171 20170313 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
3 93533432 20170310 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
4 94356672 20170307 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...

In [60]:
viewlist_exp.head(100)


Out[60]:
user_id dt goods_no spu_id brand_store_sn formar14_pv pkl_path features
0 2081602 20170307 LA12351XBE 8377053158099693598 10010460 1 /root/pickle/334/10010460/data.pkl [0.05, 1.234, 0.0, 0.027, 0.321, 0.0, 0.149, 0...
1 2081602 20170307 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
2 26471171 20170313 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
3 93533432 20170310 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
4 94356672 20170307 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
5 94356672 20170307 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
6 94356672 20170307 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
7 94356672 20170307 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
8 127228744 20170307 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
9 190085911 20170311 LA11769CCW 7951181518336483573 10010460 2 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
10 190085911 20170311 LA11769CCW 7951181518336483573 10010460 2 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
11 190085911 20170311 LA11769CCW 7951181518336483573 10010460 2 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
12 190085911 20170311 LA11769CCW 7951181518336483573 10010460 2 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
13 197403915 20170309 LA11769CCW 7951181518336483573 10010460 2 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
14 197403915 20170309 LA11769CCW 7951181518336483573 10010460 2 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
15 232075039 20170310 LA11769CCW 7951181518336483573 10010460 1 /root/pickle/334/10010460/data.pkl [0.097, 0.03, 0.0, 0.299, 0.133, 0.012, 0.239,...
16 2081602 20170307 LB14746QC8 8971246838881059027 10010460 1 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
17 25977414 20170310 LB14746QC8 8971246838881059027 10010460 4 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
18 25977414 20170310 LB14746QC8 8971246838881059027 10010460 4 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
19 25977414 20170310 LB14746QC8 8971246838881059027 10010460 4 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
20 25977414 20170310 LB14746QC8 8971246838881059027 10010460 4 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
21 25977414 20170310 LB14746QC8 8971246838881059027 10010460 1 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
22 126825162 20170308 LB14746QC8 8971246838881059027 10010460 1 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
23 190085911 20170311 LB14746QC8 8971246838881059027 10010460 2 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
24 190085911 20170311 LB14746QC8 8971246838881059027 10010460 2 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
25 213180245 20170307 LB14746QC8 8971246838881059027 10010460 1 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
26 216094334 20170307 LB14746QC8 8971246838881059027 10010460 1 /root/pickle/334/10010460/data.pkl [0.418, 0.437, 0.261, 0.286, 0.02, 0.026, 0.16...
27 2081602 20170307 LA10637QC9 8970965363904348381 10010460 3 /root/pickle/334/10010460/data.pkl [0.007, 1.391, 0.313, 0.13, 0.07, 0.0, 0.081, ...
28 2081602 20170307 LA10637QC9 8970965363904348381 10010460 3 /root/pickle/334/10010460/data.pkl [0.007, 1.391, 0.313, 0.13, 0.07, 0.0, 0.081, ...
29 2081602 20170307 LA10637QC9 8970965363904348381 10010460 3 /root/pickle/334/10010460/data.pkl [0.007, 1.391, 0.313, 0.13, 0.07, 0.0, 0.081, ...
... ... ... ... ... ... ... ... ...
70 143028060 20170307 LA10637QC9 8970965363904348381 10010460 4 /root/pickle/334/100104
limit_output extension: Maximum message size of 10000 exceeded with 18933 characters
  • Expanded view list does something with the 'expand browses' and uses formar14_pv.
  • For instances 2597.. had formar14 =4 so the expanded list repeated that row 4 times.

Descriptive Statistics


In [59]:
print('rows in buylist: {0}').format(str(len(buylist)))
print('rows in  viewlsit: {0}').format(str(len(viewlist)))
print('rows in  viewlsit expanded: {0}').format(str(len(viewlist_exp)))
print('rows in  candidates: {0}').format(str(len(candidates)))
print('rows in  candidates cluster: {0}').format(str(len(candidates)))
print('rows in  user_vec_average: {0}').format(str(len(user_vec_average)))


rows in buylist: 7506
rows in  viewlsit: 90264
rows in  viewlsit expanded: 155760
rows in  candidates: 226
rows in  candidates cluster: 226
rows in  user_vec_average: 5163

In [45]:
print('number of users in buylist: {0}').format(str(len(set(buylist.user_id.unique()))))
print('number of users in viewlist: {0}').format(str(len(set(viewlist.user_id.unique()))))
print('number of users in both sets: {0}').format(str(len(set(buylist.user_id.unique()).intersection(set(viewlist.user_id.unique())))))


number of users in buylist: 6551
number of users in viewlist: 5133
number of users in both sets: 4157

In [46]:
print('number of goods in buylist: {0}').format(str(len(set(buylist.goods_no.unique()))))
print('number of goods in viewlist: {0}').format(str(len(set(viewlist.goods_no.unique()))))
print('number of goods in both sets: {0}').format(str(len(set(buylist.goods_no.unique()).intersection(set(viewlist.goods_no.unique())))))


number of goods in buylist: 226
number of goods in viewlist: 9863
number of goods in both sets: 218

Same number of goods in candidates list as in the buylist Maybe these are the ones used for recommendations?


In [58]:
viewlist.features[3000]

He has features for all 9863 goods. Does he have the images for those?

Sessions?

Also where are the person's locations in the database?

  • are these individual sessions for the same user?

In [69]:
for uid in viewlist_exp.user_id.unique():
    print('user: {0}').format(uid)
    indices = viewlist_exp.loc[viewlist_exp.user_id==uid].index.tolist()
    print('places in database: {0}').format(indices)
    print('')


user: 2081602
places in database: [0, 1, 16, 27, 28, 29, 30531, 30532, 30889, 30890, 30891, 30984, 31004, 31015, 31028, 34136, 38488, 38492, 38610, 79836, 79837, 79838, 79839, 116105, 116106, 116116, 116119, 116120, 116198, 116200]

user: 26471171
places in database: [2, 241, 1369, 1370, 1371, 1408, 1409, 1410, 1411, 1412, 1413, 1414, 1415, 1416, 1417, 1418, 1419, 1420, 1421, 1422, 1423, 1424, 1825, 1889, 1896, 1897, 1916, 1930, 27027, 27028, 27029, 27030, 31420, 31566, 32246, 32247, 58527, 83472, 111770, 112586, 135362, 135363, 135364]

user: 93533432
places in database: [3, 1855, 31291, 31292, 90736, 90737, 90822, 143968, 143969, 143970, 144161]

user: 94356672
places in database: [4, 5, 6, 7, 503, 504, 505, 506, 1107, 1108, 1109, 1110, 1150, 1151, 1152, 1153, 1449, 1450, 1451, 1452, 2690, 2691, 2692, 2693, 2725, 2726, 2727, 2728, 31451, 31452, 31453, 31454, 69811, 69812, 69813, 69814]

user: 127228744
places in database: [8, 761, 1261, 1262, 2584, 3356, 57825, 57826, 70556, 73966, 76006, 84898, 86627, 105387, 106667, 106668, 106669, 106670, 120578, 133942, 141284, 141285, 141286, 141287, 141288, 141633, 141634, 141635]

user: 190085911
places in database: [9, 10, 11, 12, 23, 24, 410, 1270, 1275, 1276, 1871, 1872, 2405, 2406, 2807, 2808, 2938, 3285, 3576, 3577, 3855, 3856, 3857, 4023, 4274, 4275, 5264, 6044, 6173, 8300, 8523, 9157, 9158, 9889, 9890, 10945, 11813, 12576, 12577, 14080, 14081, 14089, 15286, 16070, 16218, 16219, 16220, 16221, 16290, 16291, 16292, 16293, 16372, 16373, 16374, 16375, 17059, 17060, 17061, 17741, 17742, 18103, 18104, 19196, 19197, 19854, 19855, 20965, 20966, 20970, 20971, 20972, 21907, 22152, 22153, 22390, 22447, 22448, 22877, 23516, 25817, 26779, 26877, 27458, 28487, 28488, 28622, 28721, 29495, 29496, 29800, 29801, 29935, 31469, 31470, 32387, 33081, 33379, 33380, 34269, 34270, 34271, 34272, 34273, 34274, 34275, 34276, 34277, 34278, 34279, 34280, 34281, 34282, 34283, 34284, 34285, 34286, 34287, 34288, 34289, 34290, 34629, 34630, 34631, 34632, 35544, 36980, 37098, 37099, 37655, 38191, 38192, 44666, 44667, 44668, 45028, 48767, 50860, 51663, 51982, 52406, 53765, 53766, 54028, 54177, 54559, 54560, 54561, 54562, 55779, 55854, 55855, 56256, 56266, 56470, 56471, 56472, 56780, 56831, 56854, 56855, 58688, 58901, 58902, 60253, 65328, 67846, 68139, 68140, 68627, 70854, 70855, 71545, 71546, 73412, 74048, 74286, 74287, 74451, 74667, 74668, 74669, 74670, 74856, 75094, 75905, 75906, 75907, 75908, 75909, 76953, 76954, 76955, 76956, 76957, 76958, 76959, 76960, 76961, 76962, 78466, 78518, 78519, 78597, 78598, 78599, 78640, 79278, 79279, 79620, 79763, 79764, 79765, 79766, 79767, 79768, 79769, 79770, 79882, 80005, 80006, 80007, 80008, 80009, 80857, 80858, 80859, 80979, 81114, 81826, 81827, 81828, 81829, 81830, 82252, 82253, 82399, 82400, 82408, 82409, 82630, 82631, 82640, 82641, 82642, 82840, 83087, 83088, 83089, 83090, 83091, 83283, 83284, 83576, 83721, 83757, 85731, 85732, 86372, 86762, 87972, 88028, 88440, 88487, 88596, 88597, 88598, 88599, 88600, 88740, 88999, 89086, 89319, 89829, 90038, 90039, 90289, 91179, 91180, 91643, 91644, 92801, 92934, 93667, 93733, 94194, 94195, 94738, 94739, 94740, 94741, 95861, 96687, 98984, 101778, 101929, 104736, 107164, 107165, 107166, 109970, 109971, 109972, 109973, 109974, 110290, 111139, 111140, 111141, 112900, 112901, 112980, 112981, 113155, 113700, 113701, 113702, 113703, 113704, 114114, 114290, 114896, 115196, 116170, 116390, 116391, 116392, 116539, 116717, 116718, 117145, 117166, 117327, 117413, 118073, 118103, 118878, 119774, 119875, 120610, 121032, 121033, 123869, 124588, 125939, 125940, 126650, 126651, 126760, 126788, 126831, 126832, 127586, 131170, 131171, 131172, 131173, 131174, 131175, 131176, 131177, 131178, 131179, 131180, 131181, 131182, 131183, 131184, 131185, 131186, 131187, 131188, 131189, 143107, 146363, 147760, 147761, 148011, 148304, 149828, 149829, 149830, 150326, 151392, 152596, 152936, 152937, 153894, 154718, 155256]

user: 197403915
places in database: [13, 14, 416, 417, 544, 545, 546, 547, 659, 1354, 1492, 1493, 1494, 1495, 1496, 1497, 1662, 1663, 1664, 1665, 1749, 2191, 2192, 2266, 2374, 2452, 2453, 2939, 2940, 2941, 2942, 3160, 3252, 3384, 3460, 3461, 22400, 23217, 23907, 23908, 23909, 26014, 38110, 39924, 39925, 39926, 39927, 40948, 42473, 42474, 54700, 55993, 56862, 77018, 77019, 77020, 77021, 77022, 77176, 77388, 77867, 77958, 78001, 78147, 78274, 78275, 78276, 78277, 78278, 78279, 78280, 78281, 78282, 78283, 78284, 78285, 78286, 78287, 78381, 79013, 79287, 79288, 79289, 102582, 102785, 102786, 102787, 102829, 102830, 102978, 103178, 103179, 103180, 103181, 103182, 103183, 103184, 103568, 103619, 103762, 103763, 103764, 145092]

user: 232075039
places in database: [15, 455, 1519, 1520, 14363, 14802, 15073, 15074, 15075, 15076, 15077, 15078, 15193, 15194, 15275, 16378, 36351, 37526, 37527, 37528, 37529, 37530, 37531, 39197, 39265, 39618, 40090, 40802, 40806, 40807, 40808, 40809, 41058, 42365, 42968, 43067, 58864, 58865, 66001, 66716, 66833, 68389, 83614, 84500, 84501, 85778, 106990, 107032, 108508, 108968, 109337, 109454, 109557, 109760, 109822, 109907, 110004, 110329, 110330, 110977, 110978, 110979, 110980, 110981, 110982, 110983, 110984, 111031, 111101, 111401, 111402, 111403, 111404, 111405, 111406, 111407, 111408, 112539, 112850, 112851, 113250, 113557, 113558, 113559, 113560, 113561, 113562, 113563, 114430, 114743, 114744, 114745, 114746, 114747, 114748, 114981, 115036, 115120, 115186, 115198, 115254, 115531, 115547, 115605, 115606, 115607, 115612, 115661, 115699, 115716, 115816, 115843, 115882, 115904, 115905, 115921, 115922, 115923, 115924, 115925, 115926, 115927, 115937, 115938, 115959, 115960, 115970, 115979, 116077, 116098, 116952, 117064, 117439, 118214, 118544, 118659, 118892]

user: 25977414
places in database: [17, 18, 19, 20, 21, 36, 37, 38, 39, 40, 1820, 1821, 1822, 1823, 1824, 57757, 135102, 135103, 135104, 135105, 135106, 135107, 135108, 135109, 135110, 135111, 135112, 135113, 135114, 135115, 135116, 135117, 135118, 135119, 135120, 135121, 135122, 135123, 135124, 135125, 135126, 135127, 135128, 135129, 135130, 135131, 135132]

user: 126825162
places in database: [22, 56, 57, 58, 59, 60, 1077, 1078, 1079, 1080, 1081, 1082, 2211, 2644, 3401, 9260, 58565, 63317, 72876, 72877, 72878, 76202, 76203, 104042, 112620, 113674, 114857, 114964, 141718, 142340, 142341, 142342, 143520, 143521, 143522, 150628, 150629, 150630, 150631]

user: 213180245
places in database: [25, 879, 1789, 2182, 2183, 3013, 3014, 3015, 3016, 3017, 3018, 3019, 3020, 3021, 3022, 3023, 3024, 3025, 3026, 3027, 3028, 3029, 3030, 3031, 3032, 3033, 3034, 3035, 3036, 3037, 3038, 3039, 3040, 3041, 3042, 3043, 3044, 3045, 3046, 3047, 3048, 3049, 3050, 3051, 3052, 3053, 3054, 3055, 3056, 3057, 3058, 3059, 3060, 3061, 3062, 3063, 3064, 3065, 3066, 3067, 98196, 98197, 98198, 98199, 98200, 98201, 98202, 100346, 106471, 106472, 106473, 106474, 109125, 110268, 110269, 150707, 154766]

user: 216094334
places in database: [26, 437, 732, 836, 1178, 1179, 1515, 1752, 2087, 2168, 2317, 2599, 2701, 3129, 3327, 3328, 3329, 3413, 3468, 3591, 3762, 6751, 7010, 7011, 7916, 10144, 10147, 21367, 21674, 21823, 22361, 22462, 22488, 22638, 22746, 22760, 22868, 22938, 23008, 24104, 24770, 24814, 24914, 25287, 25288, 25379, 25390, 25413, 25549, 26101, 26355, 26672, 26673, 26740, 27105, 27185, 27226, 27262, 31092, 37947, 37948, 39264, 39567, 39695, 40089, 40143, 40877, 41409, 41422, 41539, 41551, 41791, 41955, 42191, 42895, 43078, 43241, 43583, 43584, 43585, 43586, 43587, 43588, 43589, 43590, 43591, 43874, 43958, 44628, 44772, 44894, 45423, 45822, 46528, 48875, 50341, 50342, 50994, 51670, 51755, 52656, 53068, 53485, 53486, 53637, 53638, 53639, 53640, 53641, 53642, 53944, 54014, 54067, 54267, 54292, 54293, 54334, 54495, 54496, 54599, 54600, 54703, 54814, 55327, 55328, 55329, 55330, 55549, 55550, 55551, 55552, 55553, 55554, 55555, 55556, 55557, 55558, 55559, 55560, 55561, 55605, 56257, 56444, 56788, 56789, 56790, 56791, 56802, 56832, 56877, 62199, 62395, 62871, 67313, 74529, 96319, 98755, 99175, 99229, 118651, 129441, 129442, 129545, 137290, 141188]

user: 18318014
places in database: [30, 1137, 38314, 40683, 56910, 57068, 57977, 58237, 58238, 58239, 60320, 60643, 63276, 65247, 65357, 65360, 80085, 90449, 98069]

user: 20408504
places in database: [31, 32, 33, 236, 23768, 23769, 23771, 28856, 30897, 31585, 31641, 32003, 32004, 40810, 71618, 74550, 74551, 74552, 74918, 74924, 85649, 85650, 85651, 85652, 87498, 104403, 143928, 144144, 144195, 144196, 144236, 144281, 144282, 144283, 144325, 144326, 144327, 144328, 144329, 144330, 144331, 144332, 144333, 144334, 144335, 144336, 144337, 144338, 144339, 144340, 144341, 144342, 144343, 144344, 144345, 144356, 144374, 144386, 144390, 144393, 144394, 144395, 144396, 144397, 144398, 144399, 144400, 144401, 144402, 144403, 144407, 144408, 144424, 144427, 144429, 144437, 144444, 144451, 144453, 144454]

user: 25589014
places in database: [34, 35, 238, 593, 594, 595, 3963, 4086, 6408, 6439, 6450, 24074, 24120, 24121, 33268, 33269, 33270, 33271, 33272, 33273, 33274, 33275, 33276, 33277, 33278, 33279, 34030, 35669, 35670, 35671, 35672, 35673, 35880, 35881, 35882, 35883, 36683, 37367, 39085, 40994, 44174, 44758, 44759, 44774, 44775, 44776, 44777, 44778, 44779, 44861, 44862, 44863, 45103, 45104, 47393, 47477, 47501, 47502, 47503, 47504, 47505, 47506, 47515, 47516, 51009, 51271, 51272, 51273, 51274, 51275, 51276, 52548, 52549, 52550, 52551, 53789, 54259, 54290, 54651, 57127, 57128, 57129, 66223, 66224, 71619, 71620, 71621, 71622, 71623, 71624, 71625, 71626, 71627, 71628, 71629, 71630, 71631, 72076, 72077, 75076, 79844, 79845, 79846, 79847, 79937, 79938, 79939, 79940, 79941, 79942, 79943, 79944, 79945, 79946, 79947, 79948, 79949, 79950, 79951, 79952, 79953, 80087, 80088, 80089, 80090, 80091, 80092, 80093, 80094, 80095, 80096, 80389, 80390, 80391, 80392, 80393, 80505, 80506, 80507, 80508, 80509, 80510, 80511, 80512, 80513, 80514, 80515, 80516, 80517, 80518, 805
limit_output extension: Maximum message size of 10000 exceeded with 68262 characters

In [157]:
#viewlist.dt

What are the item views for each person?


In [161]:
uid = 18318014
indices = viewlist_exp.loc[viewlist_exp.user_id==uid].index.tolist()
indexlast = -1
print('single user: {0}').format(uid)
for index in indices:
    # find product 
    if index-indexlast>1:
        print('')
        #print('new session')
    print('row {0}, good number {1}  date {2}').format(index,viewlist_exp.loc[index,'goods_no'],viewlist_exp.loc[index,'dt'])
    indexlast = index.copy()


single user: 18318014

row 30, good number LA10637QC9  date 20170308

row 1137, good number LN11168QCB  date 20170308

row 38314, good number MA19QL259963  date 20170308

row 40683, good number MA19QL216545  date 20170308

row 56910, good number 523870681  date 20170308

row 57068, good number 7WP168340HOB  date 20170308

row 57977, good number 6W171036BDYH  date 20170308

row 58237, good number 6W196738HDBT  date 20170308
row 58238, good number 6W196738HDBT  date 20170308
row 58239, good number 6W196738HDBT  date 20170308

row 60320, good number 6W17113QHUI  date 20170308

row 60643, good number 6WP175005LV  date 20170308

row 63276, good number 6W189643KQ  date 20170308

row 65247, good number 12390026HEI  date 20170308

row 65357, good number 7W1611169HEI  date 20170308

row 65360, good number 12390026BAI  date 20170308

row 80085, good number YX632117W05  date 20170308

row 90449, good number B16DY10646X29  date 20170308

row 98069, good number C17LD8611HUI01  date 20170308

Dates


In [171]:
dates_per_user = np.array([])
for uid in viewlist_exp.user_id.unique():
    dates_per_user = np.append(dates_per_user,len(viewlist_exp.loc[viewlist_exp.user_id==uid,'dt'].unique()))

In [177]:
plt.hist(dates_per_user)
sns.despine()
plt.xlabel('number of dates per user')


Out[177]:
<matplotlib.text.Text at 0x12e0ece90>

In [170]:
dates_per_user


Out[170]:
array([ 20170307.,  20170313.,  20170310., ...,  20170308.,  20170307.,
        20170311.])

In [166]:
viewlist_exp.dt.unique()


Out[166]:
array([20170307, 20170313, 20170310, 20170311, 20170309, 20170308, 20170312])