Exemple #1
0
def match_dict_S1(item, user_bought_1_day_list, dict_item):
    a = frequency_cat.collocation()
    dict_utlimate = {}
    dict_item_s1 = {}
    for each in user_bought_1_day_list:
        num_item = fpm(item, each, dict_item)
        num_cat = a.cat_mat_frequency(item, each)
        n = S1(num_item, num_cat)
        dict_item_s1[each] = n
    dict_utlimate[item] = dict_item_s1
    print dict_utlimate
    return dict_utlimate
Exemple #2
0
def match_dict_S1(item, user_bought_1_day_list, dict_item):
    '''
    用户同日购买异类商品算法
    '''
    a = frequency_cat.collocation()
    dict_utlimate = {}
    dict_item_s1 = {}
    for each in user_bought_1_day_list:
        # fpm值计算
        num_item = fpm(item, each, dict_item)
        # 查询类间频率fcm
        num_cat = a.cat_mat_frequency(item, each)
        # 计算S1值
        n = S1(num_item, num_cat)
        dict_item_s1[each] = n
    dict_utlimate[item] = dict_item_s1
    print(dict_utlimate)
    return dict_utlimate
        np.dot(veca, vecb) / (np.linalg.norm(veca) * np.linalg.norm(vecb)))
    return dist


def S2(fcm, cos_value):
    '''
    计算S2值
    :param fcm:
    :param cos_value:
    :return:
    '''
    return cos_value * math.log((1 + fcm), math.e)


if __name__ == "__main__":
    a = frequency_cat.collocation()
    item_id = str(264)
    tfidf_item = open('./data/tfidf_item.txt', 'r')
    tfidf_item_all = tfidf_item.readlines()
    tfidfList = tfidf_list(item_id, tfidf_item_all)
    # print(tfidfList)
    match_items = 0
    for i in tfidf_item_all:
        itemList = i.split("|")
        goods_item = itemList[0]
        if goods_item != item_id:
            goodsTfidf = itemList[1]
            goodsTfidf = goodsTfidf.replace("[", '')
            goodsTfidf = goodsTfidf.replace("]", '')
            goodsTfidf = goodsTfidf.replace(" ", '')
            goodsTfidf = ast.literal_eval(goodsTfidf)