python - SGD算法从零开始预测电影评分
问题描述
基于这个等式,我必须计算我在下面所做的 wrt b 的导数
优化方程
def derivative_db(user_id,item_id,rating,U,V,mu,alpha):
'''In this function, we will compute dL/db_i'''
return (2*alpha*np.sum(user_id))-(2*np.sum((rating-mu-user_id-item_id-np.dot(U,V))))
但对于查询
U1, Sigma, V1 = randomized_svd(adjacency_matrix, n_components=2,n_iter=5, random_state=24)
U1.shape = (943,2)
V1.shape = (2,1681)
alpha=0.01
mu = 3.529
value=derivative_db(312,98,4,U1,V1,mu,alpha)
我应该得到答案 = -0.931
,但我得到了一个巨大的数字。
我应该在我的功能中进行哪些更正?
解决方案
你实际上误解了它。尝试使用以下代码,它将适用于您的作业。
def derivative_db(user_id,item_id,rating,U,V,mu,alpha):
'''In this function, we will compute dL/db_i'''
db=2*alpha*(b_i[user_id])-2*(rating-mu-b_i[user_id]-c_j[item_id]-np.dot(U[user_id],V[:,item_id].T))
return db
推荐阅读
- c++ - 从 C++ 中的函数返回存储的数组值
- php - 如何将txt文件中的所有数字相加并制成一个有值的变量?
- python - Keras - 无法将 numpy 数组转换为张量对象
- reactjs - React material-ui-dropzone,如何获取上传文件的完整路径
- android - 如何将recyclerview中项目的约束布局宽度设置为父宽度的百分比,而不是固定的dp值?
- c++ - std::cin 失败导致 while 循环中的循环 if 语句
- javascript - 如何创建一个可以与三个 C++ 库集成的示例电子应用程序
- javascript - 使用 Deno 读取二进制文件
- flutter - Flutter - 在构建期间调用 setState() 或 markNeedsBuild()
- sql - 循环游标获取时如何避免多个if else?