当前位置: 首页>>代码示例>>Python>>正文


Python Helper.cosine_similarity方法代码示例

本文整理汇总了Python中helper.Helper.cosine_similarity方法的典型用法代码示例。如果您正苦于以下问题:Python Helper.cosine_similarity方法的具体用法?Python Helper.cosine_similarity怎么用?Python Helper.cosine_similarity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在helper.Helper的用法示例。


在下文中一共展示了Helper.cosine_similarity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: calculate_user_top_5

# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import cosine_similarity [as 别名]
def calculate_user_top_5(user,all_apps,user_download_list):
    # ways is to calculate all_apps similarity with the user_download_list

    app_similarity={}

    for app in all_apps:
        if app in user_download_list:
            continue
        else:
            #calculate the app similarity with the user download lists
            similarity = Helper.cosine_similarity([app],user_download_list)
            if app_similarity.has_key(app):
                app_similarity[app] = app_similarity[app] + similarity
            else:
                app_similarity[app] = similarity

    #get the top 5
    top_five_apps=[]
    sorted_apps =sorted(app_similarity.items(),key=operator.itemgetter(1),reverse=True)
    i=0
    while i<5:
        #print("top 10 apps "+sorted_apps[i][0]) ## uncommnet for test one app top 10
        top_five_apps.append(sorted_apps[i][0])
        i+=1

    DataService.update_user_info({'user_id':user},{'$set':{"top_5_app":top_five_apps}})
开发者ID:wentixiaogege,项目名称:appstore-recommender,代码行数:28,代码来源:main_concurrent.py

示例2: calculate_app_top_10

# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import cosine_similarity [as 别名]
def calculate_app_top_10(app,user_download_history):
    #get app with all the lists similarity
    
    app_similarity ={}
    for apps in user_download_history:
        similarity = Helper.cosine_similarity([app],apps)
        for listapp in apps:
            if listapp is app:
                continue
            elif app_similarity.has_key(listapp):
                app_similarity[listapp] = app_similarity[listapp] + similarity
            else:
                app_similarity[listapp] = similarity
            
    if not app_similarity.has_key(app):
        return 
    #remove itself
    #app_similarity.pop(app)
    #calculate top10  reverse= true means from bigger to smaller   
    #items() and operator.itemgetter(1) means get list of tuples with key-value pair
    sorted_apps =sorted(app_similarity.items(),key=operator.itemgetter(1),reverse=True)

    top_ten_apps=[]

    i=0
    while i<10:
        #print("top 10 apps "+sorted_apps[i][0]) ## uncommnet for test one app top 10
        top_ten_apps.append(sorted_apps[i][0])
        i+=1
开发者ID:wentixiaogege,项目名称:appstore-recommender,代码行数:31,代码来源:main_concurrent.py


注:本文中的helper.Helper.cosine_similarity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。