import tensorflow as tf # Model parameters W = tf.Variable([.3], dtype=tf.float32) #variables assignades que poden ser + o - correctes b = tf.Variable([-.3], dtype=tf.float32) # Model input and output x = tf.placeholder(tf.float32) linear_model = W * x + b # model que utilitzem y = tf.placeholder(tf.float32) # loss calcula el marge de error amb el nostre model loss = tf.reduce_sum(tf.square(linear_model - y)) # sum of the squares # optimizer optimtza les variables w i b per fer el codi mes "inteligent" va ajustanse a ritme de 0.01 optimizer = tf.train.GradientDescentOptimizer(0.01) train = optimizer.minimize(loss) # training data x_train = [1, 2, 3, 4] y_train = [0, -1, -2, -3] # 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}) # evaluate training accuracy curr_W, curr_b, curr_loss = sess.run([W, b, loss], {x: x_train, y: y_train}) #guardem a les variables curr_w,curr_b, curr_loss, les variables que "hem tobat durant la execuccio" print("W: %s b: %s loss: %s" % (curr_W, curr_b, curr_loss))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question