Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tensorflow as tf
- import numpy as np
- import matplotlib.pyplot as plt
- x = np.array([0,1,2,3,4,5,6,7,8,9,10])
- y = np.array([1,3,5,7,9,11,13,15,17,19,21])
- plt.plot(x,y, "k")
- plt.show()
- inputt = tf.placeholder(dtype = tf.float64, shape = None)
- output = tf.placeholder(dtype = tf.float64, shape = None)
- slope = tf.Variable(4, dtype=tf.float64)
- b = tf.Variable(5 , dtype=tf.float64)
- model_operation = slope * inputt + b
- error = output - model_operation
- squared = error ** 2
- loss = tf.reduce_mean(squared)
- opt = tf.train.GradientDescentOptimizer(0.0005)
- train = opt.minimize(loss)
- init = tf.global_variables_initializer()
- with tf.Session()as sess:
- sess.run(init)
- for i in range(20000):
- sess.run(train, feed_dict={inputt:x, output:y})
- if i % 10 ==0:
- print(sess.run([slope, b]))
- plt.plot(x, sess.run(model_operation, feed_dict={inputt:x}))
- plt.plot(x,y, "k")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement