码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Machine learning week 9(Andrew Ng)


    文章目录

      • Recommender systems
        • 1.Collaborative filtering
          • 1.1 Making recommendations
          • 1.2 Using per-item features
          • 1.3 Collaborative Filtering algorithm
          • 1.4.Binary labels: favs, likes and clicks
          • 1.5.Mean normalization
          • 1.6.TensorFlow
          • 1.7.Finding related items
        • 2. Content-based filtering
          • 2.1. Collaborative filtering vs Content-based filtering
          • 2.2. Deep learning for content-based filtering
          • 2.3. Recommending from a large catalog

    Recommender systems

    1.Collaborative filtering

    1.1 Making recommendations

    Introduction

    1.2 Using per-item features

    在这里插入图片描述
    Cost function:
    在这里插入图片描述

    1.3 Collaborative Filtering algorithm

    Predict x feature via the known parameters w w w and b b b
    在这里插入图片描述
    The cost function is similar to before.
    在这里插入图片描述

    # Y (4778, 443) R (4778, 443)
    # X (443, 10)
    # W (443, 10)
    # b (1, 443)
    # num_features 10
    # num_movies 4778
    # num_users 443
    def cofi_cost_func(X, W, b, Y, R, lambda_):
        """
        Returns the cost for the content-based filtering
        Args:
          X (ndarray (num_movies,num_features)): matrix of item features
          W (ndarray (num_users,num_features)) : matrix of user parameters
          b (ndarray (1, num_users)            : vector of user parameters
          Y (ndarray (num_movies,num_users)    : matrix of user ratings of movies
          R (ndarray (num_movies,num_users)    : matrix, where R(i, j) = 1 if the i-th movies was rated by the j-th user
          lambda_ (float): regularization parameter
        Returns:
          J (float) : Cost
        """
        nm, nu = Y.shape
        J = 0
        ### START CODE HERE ###  
        for j in range(nu):
            w = W[j,:]
            b_j = b[0,j]
            for i in range(nm):
                x = X[i,:]
                J += R[i,j] * ((np.dot(w,x) + b_j - Y[i,j])**2)
        J /= 2 
        J += (lambda_ / 2) * (np.sum(np.square(W)) + np.sum(np.square(X)))
        ### END CODE HERE ### 
    
        return J
    
    
    def cofi_cost_func_v(X, W, b, Y, R, lambda_):
        """
        Returns the cost for the content-based filtering
        Vectorized for speed. Uses tensorflow operations to be compatible with custom training loop.
        Args:
          X (ndarray (num_movies,num_features)): matrix of item features
          W (ndarray (num_users,num_features)) : matrix of user parameters
          b (ndarray (1, num_users)            : vector of user parameters
          Y (ndarray (num_movies,num_users)    : matrix of user ratings of movies
          R (ndarray (num_movies,num_users)    : matrix, where R(i, j) = 1 if the i-th movies was rated by the j-th user
          lambda_ (float): regularization parameter
        Returns:
          J (float) : Cost
        """
        j = (tf.linalg.matmul(X, tf.transpose(W)) + b - Y)*R
        J = 0.5 * tf.reduce_sum(j**2) + (lambda_/2) * (tf.reduce_sum(X**2) + tf.reduce_sum(W**2))
        return J
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    1.4.Binary labels: favs, likes and clicks

    Judge whether the customer likes it(Binary labels)
    在这里插入图片描述

    1.5.Mean normalization

    在这里插入图片描述
    And in fact, the effect of this algorithm is it will cause the initial guesses for the new user Eve to be just equal to the mean of whatever other users have rated these five movies. And that seems more reasonable to take the average rating of the movies rather than to guess that all the ratings by Eve will be zero.

    1.6.TensorFlow
    1.7.Finding related items

    在这里插入图片描述

    2. Content-based filtering

    2.1. Collaborative filtering vs Content-based filtering

    在这里插入图片描述


    Our purpose is to predict the value, so we should transform the features of users and movies to vector v u , v m v_u,v_m vu​,vm​, which have the same dimension.
    在这里插入图片描述

    2.2. Deep learning for content-based filtering

    在这里插入图片描述
    Both of them have 32 numbers although x u x_u xu​ and x m x_m xm​ are different.
    在这里插入图片描述
    And ∣ ∣ v m ( k ) − v m ( i ) ∣ ∣ m i n 2 ||v_m^{(k)}-v_m^{(i)}||^2_{min} ∣∣vm(k)​−vm(i)​∣∣min2​ is the most similar movie to movie i i i.

    2.3. Recommending from a large catalog

    When the catalog is too large, thousands of millions of times every time a user shows up on your website becomes computationally infeasible. So, we should prepare before.
    Having precomputed the most similar movies to every movie, we can just pull up the results using a look-up table. And then we can retrieval and rank
    在这里插入图片描述在这里插入图片描述
    Rank them by the prediction value from high to low.

  • 相关阅读:
    JCTC:基于PWmat中的混合溶剂模型精确计算离子溶解自由能
    【数据结构初阶】初始二叉树 -- (二叉树基础概念+二叉树的顺序结构及实现)
    SpringBoot自动装配原理
    网上商城建设:微信小程序直播申请开通流程及开通方法
    交换机和路由器技术-25-OSPF多区域配置
    算法与数据结构 --- 栈和队列的定义与特点,以及案例引入
    @AutoConfigurationPackage注解类
    C++所有容器的详细使用介绍
    Android 10 如何自定义屏保功能
    A. Grasshopper on a Line
  • 原文地址:https://blog.csdn.net/weixin_62012485/article/details/126581928
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号