nandovallec commited on
Commit
47eae45
1 Parent(s): ca1429e

Not allow repeated

Browse files
Files changed (1) hide show
  1. recommender.py +7 -6
recommender.py CHANGED
@@ -29,7 +29,7 @@ def get_best_tid(current_list, ps_matrix_row, K=50, MAX_tid=10):
29
  topK_pid = [i for i, _ in sortedList[1:K + 1]]
30
 
31
  n = 0
32
-
33
  while (1):
34
 
35
  top_pid = topK_pid[n]
@@ -37,7 +37,8 @@ def get_best_tid(current_list, ps_matrix_row, K=50, MAX_tid=10):
37
  add_tid_list = df_ps_train.loc[top_pid].tid
38
 
39
  # Form new list
40
- new_tid_list = current_list + add_tid_list
 
41
  new_tid_list = list(dict.fromkeys(new_tid_list))
42
 
43
  # Check number of songs and Add to data for prediction
@@ -46,15 +47,15 @@ def get_best_tid(current_list, ps_matrix_row, K=50, MAX_tid=10):
46
  if (total_song > MAX_tid):
47
  new_tid_list = new_tid_list[:MAX_tid]
48
  # Add
49
- current_list = new_tid_list
50
  break
51
  else:
52
- current_list = new_tid_list
53
  n += 1
54
  if (n == K):
55
  break
56
 
57
- return current_list
58
 
59
 
60
  def inference_from_tid(list_tid, K=50, MAX_tid=10):
@@ -78,4 +79,4 @@ def inference_from_uri(list_uri, K=50, MAX_tid=10):
78
  with open('model/dict_tid2uri.pkl', 'rb') as f:
79
  dict_tid2uri = pickle.load(f)
80
  best_uri = [dict_tid2uri[x] for x in best_tid]
81
- return best_uri
 
29
  topK_pid = [i for i, _ in sortedList[1:K + 1]]
30
 
31
  n = 0
32
+ new_list = []
33
  while (1):
34
 
35
  top_pid = topK_pid[n]
 
37
  add_tid_list = df_ps_train.loc[top_pid].tid
38
 
39
  # Form new list
40
+ new_tid_list = new_list + add_tid_list
41
+ new_tid_list = [x for x in new_tid_list if x not in current_list]
42
  new_tid_list = list(dict.fromkeys(new_tid_list))
43
 
44
  # Check number of songs and Add to data for prediction
 
47
  if (total_song > MAX_tid):
48
  new_tid_list = new_tid_list[:MAX_tid]
49
  # Add
50
+ new_list = new_tid_list
51
  break
52
  else:
53
+ new_list = new_tid_list
54
  n += 1
55
  if (n == K):
56
  break
57
 
58
+ return new_list
59
 
60
 
61
  def inference_from_tid(list_tid, K=50, MAX_tid=10):
 
79
  with open('model/dict_tid2uri.pkl', 'rb') as f:
80
  dict_tid2uri = pickle.load(f)
81
  best_uri = [dict_tid2uri[x] for x in best_tid]
82
+ return best_uri