登录 注册
当前位置:主页 > 资源下载 > 10 > 源代码 集体智慧编程

源代码 集体智慧编程

  • 更新:2024-06-07 16:51:38
  • 大小:236KB
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:机器学习 - 人工智能
  • 格式:ZIP

资源介绍

集体智慧编程 源代码. from pydelicious import get_popular,get_userposts,get_urlposts import time def initializeUserDict(tag,count=5): user_dict={} # get the top count' popular posts for p1 in get_popular(tag=tag)[0:count]: # find all users who posted this for p2 in get_urlposts(p1['href']): user=p2['user'] user_dict[user]={} return user_dict def fillItems(user_dict): all_items={} # Find links posted by all users for user in user_dict: for i in range(3): try: posts=get_userposts(user) break except: print "Failed user "+user+", retrying" time.sleep(4) for post in posts: url=post['href'] user_dict[user][url]=1.0 all_items[url]=1 # Fill in missing items with 0 for ratings in user_dict.values(): for item in all_items: if item not in ratings: ratings[item]=0.0