Building Machine Learning Projects with TensorFlow by 2016

Building Machine Learning Projects with TensorFlow by 2016

Author:2016
Language: eng
Format: mobi, epub
Publisher: Packt Publishing


X = tf.placeholder("float") Y = tf.placeholder("float") # Create first hidden layer hw1 = tf.Variable(tf.random_normal([1, 10], stddev=0.1)) # Create output connection ow = tf.Variable(tf.random_normal([10, 1], stddev=0.0)) # Create bias b = tf.Variable(tf.random_normal([10], stddev=0.1)) model_y = model(X, hw1, b, ow) # Cost function cost = tf.pow(model_y-Y, 2)/(2) # construct an optimizer train_op = tf.train.GradientDescentOptimizer(0.05).minimize(cost) # Launch the graph in a session with tf.Session() as sess: tf.initialize_all_variables().run() #Initialize all variables for i in range(1,100): dsX, dsY = shuffle (dsX.transpose(), dsY) #We randomize the samples to mplement a better training trainX, trainY =dsX[0:trainsamples], dsY[0:trainsamples] for x1,y1 in zip (trainX, trainY): sess.run(train_op, feed_dict={X: [[x1]], Y: y1}) testX, testY = dsX[trainsamples:trainsamples + testsamples], dsY[0:trainsamples:trainsamples+testsamples] cost1=0. for x1,y1 in zip (testX, testY): cost1 += sess.run(cost, feed_dict={X: [[x1]], Y: y1}) / testsamples if (i%10 == 0): print "Average cost for epoch " + str (i) + ":" + str(cost1)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.