import matplotlib.pyplot as plt
%matplotlib inline
复制代码
plt.scatter(data_x, data_y)
复制代码
<matplotlib.collections.PathCollection at 0x10dbfe908>
复制代码
import tensorflow as tf
复制代码
/anaconda3/envs/py35/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: compiletime version 3.6 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.5
return f(*args, **kwds)
/anaconda3/envs/py35/lib/python3.5/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
复制代码
w = tf.Variable(1., name='quanzhong')
b = tf.Variable(0., name='pianzhi')
复制代码
x = tf.placeholder(tf.float32, shape=None)
复制代码
y = tf.placeholder(tf.float32, shape=[None])
复制代码
pred = tf.multiply(x, w) + b
复制代码
loss = tf.reduce_sum(tf.squared_difference(pred, y))
复制代码
for i in range(10000):
sess.run(train_step, feed_dict={x:data_x, y:data_y})
if i%1000 == 0:
print(sess.run([loss, w ,b], feed_dict={x:data_x, y:data_y}))
复制代码