我想要创建一个简单的电影推荐系统,其中Y(i,j)表示第j个用户对第i部电影的评分,如果一部电影被评分则R(i,j)=1,否则r(i,j)=0

import tensorflow as tfimport pymatlab as matimport numpy as npimport matplotlib.pyplot as pltimport scipy.iomat=scipy.io.loadmat('ex8_movies.mat')Y=mat['Y']R=mat['R']plt.interactive(False)#plt.plot(Y)#plt.show()print(Y[R==1])#print(Y[R==0])r=tf.constant(R,dtype=tf.float32)params=scipy.io.loadmat('ex8_movieParams.mat')num_users = params['num_users']num_movies =params['num_movies']num_features=params['num_features']print("shape of Y:",np.shape(Y))print(num_users)print(num_movies)x=np.random.rand(1682,2)X=tf.placeholder(tf.float32,([1682 ,2]))#X=tf.Variable(tf.zeros([1682,943]),dtype=tf.float32)thetas=tf.Variable(tf.zeros([943,2]),dtype=tf.float32)y=tf.placeholder(tf.float32,[1682 ,943])sess=tf.InteractiveSession()init = tf.global_variables_initializer()sess.run(init)#print((np.transpose(thetas)))j_temp=tf.square(tf.matmul(X,tf.transpose(thetas))- y)j_temp=j_temp([R==1])cost=tf.reduce_mean(tf.reduce_sum(j_temp))optimizer=tf.train.GradientDescentOptimizer(0.09).minimize(cost)sess.run(j_temp,{X:x,y:Y})#sess.run(j_tmp)sess.run(cost)print("slodvhbdfh\n\n")print(Y[R==0])

我想要创建一个简单的电影推荐系统,其中Y(i,j)表示第j个用户对第i部电影的评分,如果一部电影被评分则R(i,j)=1,否则r(i,j)=0。我遇到了以下错误:

"C:\Python\python interpreter\pythonw.exe" C:/Python/Projects/recommend.py[5 4 4 ..., 2 3 3]shape of Y: (1682, 943)[[943]][[1682]]File "C:/Python/Projects/recommend.py", line 38, in <module>j_temp=j_temp([R==1])TypeError: 'Tensor' object is not callableProcess finished with exit code 1

回答:

identifier(arguments) 是Python中调用函数的语法。你试图用一个张量来这样做,但张量并不是函数——你不能调用它。你到底想做什么?我无法判断,因为你没有在文本、注释中提供任何描述,甚至连变量名都没有用到有意义的名称上。

此外,构造 `[R==1]` 在Python中是不合法的。如果你想获取该用户的所有已评分电影,你需要复习一下如何对张量应用过滤器的语法。这些关键词应该能引导你找到答案。

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注