|
@@ -6,7 +6,7 @@ import json
|
|
|
if __name__=="__main__":
|
|
|
#1.load data
|
|
|
nowdate=sys.argv[1]
|
|
|
- f = open("./data/user_item_share_"+nowdate)
|
|
|
+ f = open("./data/user_item_share_filter_"+nowdate)
|
|
|
user_item_dict={}
|
|
|
item_dict = {}
|
|
|
while True:
|
|
@@ -34,6 +34,35 @@ if __name__=="__main__":
|
|
|
else:
|
|
|
item_dict[vid] = item_dict[vid]+1
|
|
|
f.close()
|
|
|
+ nowhour=sys.argv[2]
|
|
|
+ f1 = open("./data/user_cur_day_item_share_filter_"+nowhour)
|
|
|
+ while True:
|
|
|
+ line = f1.readline()
|
|
|
+ if not line:
|
|
|
+ break
|
|
|
+ items = line.strip().split("\t")
|
|
|
+ if len(items)<3:
|
|
|
+ continue
|
|
|
+ vid = -1
|
|
|
+ try:
|
|
|
+ vid = int(items[2])
|
|
|
+ except:
|
|
|
+ continue
|
|
|
+ if vid == -1:
|
|
|
+ continue
|
|
|
+
|
|
|
+ key = (items[1],vid)
|
|
|
+ #print(key)
|
|
|
+ if key not in user_item_dict:
|
|
|
+ user_item_dict[key] = 1
|
|
|
+ else:
|
|
|
+ user_item_dict[key] = user_item_dict[key]+1
|
|
|
+ if vid not in item_dict:
|
|
|
+ item_dict[vid] = 1
|
|
|
+ else:
|
|
|
+ item_dict[vid] = item_dict[vid]+1
|
|
|
+ f1.close()
|
|
|
+
|
|
|
#((user,item), score)
|
|
|
#print(user_item_dict)
|
|
|
#2. (uid, [(vid, score)....])
|
|
@@ -87,8 +116,9 @@ if __name__=="__main__":
|
|
|
pair_score = v
|
|
|
if item1 in item_dict:
|
|
|
item_score1 = item_dict[item1]
|
|
|
- if item_score1<10:
|
|
|
- continue
|
|
|
+ #if item_score1<10:
|
|
|
+ # continue
|
|
|
+ item_score1 = 1
|
|
|
i2i_pro = float(pair_score)/(float(item_score1)+5)
|
|
|
if i2i_pro<0.000001:
|
|
|
continue
|
|
@@ -102,8 +132,9 @@ if __name__=="__main__":
|
|
|
rec_item_dict[item2] = rec_list1
|
|
|
if item2 in item_dict:
|
|
|
item_score2 = item_dict[item2]
|
|
|
- if item_score2<10:
|
|
|
- continue
|
|
|
+ #if item_score2<10:
|
|
|
+ # continue
|
|
|
+ item_score2 = 1.0
|
|
|
i2i_pro = float(pair_score)/(float(item_score2)+5)
|
|
|
if i2i_pro<0.000001:
|
|
|
continue
|
|
@@ -139,7 +170,7 @@ if __name__=="__main__":
|
|
|
final_rec_list.append((k, sorted_v))
|
|
|
#print(final_rec_list[:1])
|
|
|
#json_str = json.dumps(final_rec_list)
|
|
|
- with open("./data/rec_result_"+nowdate+".json", "w") as f :
|
|
|
+ with open("./data/rec_result3_"+nowhour+".json", "w") as f :
|
|
|
json.dump(final_rec_list, f)
|
|
|
|
|
|
|