【发布时间】:2018-04-09 19:45:50
【问题描述】:
我是 tensorflow 环境的新手,我在 Jupyter-notebook 中编写了这段代码,并且损失函数正在迅速增加。
我使用梯度下降作为优化器,学习率为0.05。
如果将学习率改为0.0000005,那么损失在101.82左右
----------------------------------------------- -------------------
我不知道该怎么办。
import pandas as pd
import matplotlib.pyplot as plt
import tensorflow as tf
from __future__ import division
x = tf.placeholder(tf.float32)
#x = tf.placeholder(tf.float32)
y = tf.placeholder(tf.float32)
b = tf.Variable([1.0], tf.float32)
w1 = tf.Variable([1.0], tf.float32)
init = tf.Session()
lin_mod = w1 * x + b
squared_delta = tf.square(lin_mod - y)
loss = tf.reduce_sum(squared_delta)
my_opt = tf.train.GradientDescentOptimizer(0.05)
train = my_opt.minimize(loss)
x_train = [
237,
229.5,
232.45,
207.4,
205.65,
207.3,
]
]
y_train = [237,
230,
233,
207.2,
208.9,
207.5,
]
sess = tf.Session()
init = tf.global_variables_initializer()
sess.run(init)
for i in range(100):
print(sess.run(train, {x:x_train, y:y_train}))
print(sess.run(loss, {x:x_train, y:y_train}))
None
209335760000.0
None
8.30988e+21
None
3.298725e+32
None
inf
Non
【问题讨论】:
-
“我不知道,该怎么办”并不是一个真正的问题。那么你的问题是什么?另请阅读How do I ask a good question? 和How to create a Minimal, Complete, and Verifiable example
标签: python pandas tensorflow linear-regression