【发布时间】:2017-07-27 10:19:28
【问题描述】:
我正在尝试下面的简单线性 reg 梯度下降示例是我的代码...
def gardientDecent(features,target):
alpha = tf.constant(0.001,dtype=tf.float64)
length = tf.cast(tf.size(target),dtype=tf.float64)
feature_one = features[:,0]
features_Val = tf.transpose(features)
dummy_theta = tf.zeros([2,1],dtype=tf.float64)
dot_product = tf.multiply(features_Val, dummy_theta)
diff = tf.subtract(dot_product, target)
diff_one = tf.multiply(diff, feature_one)
theta1 = tf.reduce_sum(diff)
theta2 = tf.reduce_sum(diff_one)
final1 = tf.div(theta1, length)
final2 = tf.div(theta2, length)
t1 = tf.subtract(theta1, tf.multiply(alpha, final1))
t2 = tf.subtract(theta2, tf.multiply(alpha, final2))
newArray = np.array([[0],[0]],dtype=np.float64)
for i in range(1000):
temp1,temp2 = vas.run([t1,t2],{dummy_theta:newArray})
print i ,temp1,temp2
newArray = np.array([[temp1],[temp2]],dtype=np.float64)
print vas.run(tf.cast(newArray,dtype=tf.float64))
但是在经过几步之后运行时,我得到了这样的 Nan 值...
请帮助我......我是 ML 和 Tensor 流的新手......提前 TY
【问题讨论】:
-
请不要张贴代码图片,它们不能被复制粘贴并且难以阅读。编辑您的帖子。
-
@gionni 现已修改
标签: python arrays machine-learning tensorflow