【发布时间】:2017-07-10 16:03:25
【问题描述】:
import tensorflow as tf
import pymatlab as mat
import numpy as np
import matplotlib.pyplot as plt
import scipy.io
mat=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 callable
Process finished with exit code 1
【问题讨论】:
-
请提供您目前尝试过的示例代码
-
是的,我用示例代码编辑了它
-
您好,欢迎来到 Stack Overflow,请花点时间通过 welcome tour 了解您在此处的方式(并获得您的第一个徽章),阅读如何创建 Minimal, Complete, and Verifiable example并检查How to Ask Good Questions,这样您就有机会获得反馈和有用的答案。
标签: python numpy machine-learning tensorflow tensor