《Python数据分析与挖掘实战》第12章(下)——协同推荐1 基于物品的协同过滤推荐2 随机推荐3 按照流行度推荐

    # 确定用户未浏览的网页(可推荐的)的数据表格
    TEST = 1-df_test
    test2 = DataFrame(TEST, index = test.columns, columns=test.index)
    print test2.head()
    print test2.shape 
    
    # 确定网页浏览热度排名:
    hotPopular = data['fullURL'].value_counts()
    hotPopular = pd.DataFrame(hotPopular)
    print hotPopular.head()
    print hotPopular.shape 
    
    # 按照流行度对可推荐的所有网址排序
    test3 = test2.reset_index()
    list_custom = list(hotPopular.index)
    test3['index'] = test3['index'].astype('category')
    test3['index'].cat.reorder_categories(list_custom, inplace=True)
    test3.sort_values('index',inplace = True)
    test3.set_index ('index', inplace = True)
    print test3.head()
    print test3.shape 
    
    
    # 按照流行度为用户推荐3个未浏览过的网址
    recomMatrix = test3
    start5 = time.clock()
    popular_result = popular_recommed(3, recomMatrix)
    end5 = time.clock()
    print '按照流行度为用户推荐3个未浏览过的网址耗时为' + str(end5 - start5)+'s!'#7.70043007471s!
    
    #保存的表名命名格式为“3_1_k此表功能名称”,是本小节生成的第6张表格,功能为popular_result:显示按流行度推荐的结果
    popular_result.to_csv('3_1_6popular_result.csv')
    
    popular_result
[/code]

![](https://img-
blog.csdn.net/20180214092344232?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMjA2Mzc3Mw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)

至此,本章所有内容分享完毕

  
  
** 备注:本章完整代码请见 [ 点击打开链接
](https://github.com/clover95/DataAnalysisbyPython/tree/master/chapter12) **


![在这里插入图片描述](https://img-blog.csdnimg.cn/20210608151750993.gif)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值