comparison Code/eda.py @ 16:68b8b088f50a

Code for pre-training
author Paulo Chiliguano <p.e.chiilguano@se14.qmul.ac.uk>
date Mon, 27 Jul 2015 19:24:37 +0100
parents 2e3c57fba632
children ee13c193c76e
comparison
equal deleted inserted replaced
15:2e3c57fba632 16:68b8b088f50a
3 Created on Wed Jul 22 17:42:09 2015 3 Created on Wed Jul 22 17:42:09 2015
4 4
5 @author: paulochiliguano 5 @author: paulochiliguano
6 """ 6 """
7 7
8
9 import random
8 import numpy as np 10 import numpy as np
9 from sklearn import mixture 11 from sklearn import mixture
10 12
11 #User-item dictionary 13 #User-item dictionary
12 users = {"Angelica": {"SOAJJPC12AB017D63F": 3.5, "SOAKIXJ12AC3DF7152": 2.0, 14 users = {"Angelica": {"SOAJJPC12AB017D63F": 3.5, "SOAKIXJ12AC3DF7152": 2.0,
36 "Veronica": {"SOAJJPC12AB017D63F": 3.0, "SOAKPFH12A8C13BA4A": 5.0, 38 "Veronica": {"SOAJJPC12AB017D63F": 3.0, "SOAKPFH12A8C13BA4A": 5.0,
37 "SOAGTJW12A6701F1F5": 4.0, "SOAKWCK12A8C139F81": 2.5, 39 "SOAGTJW12A6701F1F5": 4.0, "SOAKWCK12A8C139F81": 2.5,
38 "SOAKNZI12A58A79CAC": 3.0} 40 "SOAKNZI12A58A79CAC": 3.0}
39 } 41 }
40 42
41 items = {"SOAJJPC12AB017D63F": [2.5, 4, 3.5, 3, 5, 4, 1], 43 items = {"SOAJJPC12AB017D63F": [2.5, 4, 3.5, 3, 5, 4, 1, 5, 4, 1],
42 "SOAKIXJ12AC3DF7152": [2, 5, 5, 3, 2, 1, 1], 44 "SOAKIXJ12AC3DF7152": [2, 5, 5, 3, 2, 1, 1, 5, 4, 1],
43 "SOAKPFH12A8C13BA4A": [1, 5, 4, 2, 4, 1, 1], 45 "SOAKPFH12A8C13BA4A": [1, 5, 4, 2, 4, 1, 1, 5, 4, 1],
44 "SOAGTJW12A6701F1F5": [4, 5, 4, 4, 1, 5, 1], 46 "SOAGTJW12A6701F1F5": [4, 5, 4, 4, 1, 5, 1, 5, 4, 1],
45 "SOAKWCK12A8C139F81": [1, 4, 5, 3.5, 5, 1, 1], 47 "SOAKWCK12A8C139F81": [1, 4, 5, 3.5, 5, 1, 1, 5, 4, 1],
46 "SOAKNZI12A58A79CAC": [1, 5, 3.5, 3, 4, 5, 1], 48 "SOAKNZI12A58A79CAC": [1, 5, 3.5, 3, 4, 5, 1, 5, 4, 1],
47 "SOAJZEP12A8C14379B": [5, 5, 4, 2, 1, 1, 1], 49 "SOAJZEP12A8C14379B": [5, 5, 4, 2, 1, 1, 1, 5, 4, 1],
48 "SOAHQFM12A8C134B65": [2.5, 4, 4, 1, 1, 1, 1]} 50 "SOAHQFM12A8C134B65": [2.5, 4, 4, 1, 1, 1, 1, 5, 4, 1]}
49 51 '''
50 profile = {"Profile0": [2.5, 4, 3.5, 3, 5, 4, 1], 52 profile = {"Profile0": [2.5, 4, 3.5, 3, 5, 4, 1],
51 "Profile1": [2.5, 4, 3.5, 3, 5, 4, 1], 53 "Profile1": [2.5, 4, 3.5, 3, 5, 4, 1],
52 "Profile2": [2.5, 4, 3.5, 3, 5, 4, 1], 54 "Profile2": [2.5, 4, 3.5, 3, 5, 4, 1],
53 "Profile3": [2.5, 4, 3.5, 3, 5, 4, 1], 55 "Profile3": [2.5, 4, 3.5, 3, 5, 4, 1],
54 "Profile4": [2.5, 4, 3.5, 3, 5, 4, 1], 56 "Profile4": [2.5, 4, 3.5, 3, 5, 4, 1],
55 "Profile5": [2.5, 4, 3.5, 3, 5, 4, 1], 57 "Profile5": [2.5, 4, 3.5, 3, 5, 4, 1],
56 "Profile6": [2.5, 4, 3.5, 3, 5, 4, 1], 58 "Profile6": [2.5, 4, 3.5, 3, 5, 4, 1],
57 "Profile7": [2.5, 4, 3.5, 3, 5, 4, 1]} 59 "Profile7": [2.5, 4, 3.5, 3, 5, 4, 1]}
58 60 '''
59
60 61
62 '''
63 Generate M individuals uniformly
64 '''
65 np.random.seed(len(users))
66 M = np.random.uniform(1, 5, len(users) * len(items.values()[0]))
67 M.shape = (-1, len(items.values()[0]))
68 profile = {}
69 i = 0
70 for row in M.tolist():
71 profile["Profile" + str(i)] = M.tolist()[i]
72 i = i + 1
61 73
62 np.random.seed(1) 74 np.random.seed(1)
63 g = mixture.GMM(n_components=7) 75 g = mixture.GMM(n_components=7)
64 # Generate random observations with two modes centered on 0 76 # Generate random observations with two modes centered on 0
65 # and 10 to use for training. 77 # and 10 to use for training.