def get_hated_sim(uid, eid): u_his = user_event[user_event.user_id == uid] hated = u_his.at[u_his.index[0], 'declined'].split() score = [] feature = [0, 0, 0] if (len(hated) == 0): return feature # get tf-idf vector of eid e = event_tfidf[event_tfidf.event_id == eid] vec_e = list(e.ix[e.index[0], 1:]) # get tf-idf vector of hated events h_e = event_tfidf[event_tfidf.event_id.isin(hated)] for i in range(len(h_e)): vec_he = list(h_e.ix[h_e.index[i], 1:]) score.append(formula.cos_sim(vec_e, vec_he)) feature[0] = min(score) feature[1] = max(score) feature[2] = sum(score) / len(hated) return feature
def get_interested_sim(uid, eid): u_his = user_event[user_event.user_id == uid] interested = u_his.at[u_his.index[0], 'attend'].split() + u_his.at[u_his.index[0], 'maybe'].split() score = [] feature = [0, 0, 0] if (len(interested) == 0): return feature # get tf-idf vector of eid e = event_tfidf[event_tfidf.event_id == eid] vec_e = list(e.ix[e.index[0], 1:]) # get tf-idf vector of interested events i_e = event_tfidf[event_tfidf.event_id.isin(interested)] for i in range(len(i_e.index)): vec_ie = list(i_e.ix[i_e.index[i], 1:]) score.append(formula.cos_sim(vec_e, vec_ie)) feature[0] = min(score) feature[1] = max(score) feature[2] = sum(score) / len(interested) return feature