Created
December 30, 2017 00:33
-
-
Save kuc-arc-f/c5c9f8230b7265f330933865bc69333e to your computer and use it in GitHub Desktop.
tensorFlow sample, for IoT data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
if __name__ == "__main__": | |
# Model parameters | |
W = tf.Variable([0.0], dtype=tf.float32) | |
b = tf.Variable([0.0], dtype=tf.float32) | |
# Model input and output | |
x = tf.placeholder(tf.float32) | |
y = tf.placeholder(tf.float32) | |
linear_model = W*x + b | |
# loss | |
loss = tf.reduce_sum(tf.square(linear_model - y)) # sum of the squares | |
# optimizer | |
optimizer = tf.train.GradientDescentOptimizer(0.01) | |
train = optimizer.minimize(loss) | |
# training data | |
x_train = [0.01, 0.02 , 0.03, 0.04, 0.05 ] | |
y_train = [0.13, 0.12 , 0.06, 0.11, 0.13 ] | |
# training loop | |
init = tf.global_variables_initializer() | |
sess = tf.Session() | |
sess.run(init) # reset values to wrong | |
for i in range(1000): | |
sess.run(train, {x: x_train, y: y_train}) | |
if i % 100 == 0: | |
print( i, sess.run(W), sess.run(b) ) | |
# evaluate training accuracy | |
curr_W, curr_b, curr_loss = sess.run([W, b, loss], {x: x_train, y: y_train}) | |
print("W: %s b: %s loss: %s"%(curr_W, curr_b, curr_loss)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment