#!/usr/bin/env python2
-- coding: utf-8 --
“”"
Created on Thu Dec 20 10:20:55 2018
@author: prestonhuang
“”"
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
train_X = np.linspace(-1,1,100)
train_Y = 2*train_X + np.random.randn(train_X.shape) 0.3 # y=2x
plt.plot(train_X,train_Y,‘ro’,label = ‘Original data’)
plt.legend()
plt.show()
X = tf.placeholder(‘float’)
Y = tf.placeholder(‘float’)
W = tf.Variable(tf.random_normal([1]), name = ‘Weight’)
b = tf.Variable(tf.zeros([1]), name =‘bias’)
z = tf.multiply(X,W) + b
#反向传播
cost = tf.reduce_mean(tf.square(Y - z))#平均值,平方
learning_rate = 0.01
optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)
int = tf.gl