Advanced Data Analytics Using Python_ With Machine Learning, Deep Learning and NLP Examples ( 2023)
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Chapter 5
Deep Learning and Neural Networks
W = tf.Variable(tf.random_normal([X_train.
shape[1],1],stddev=.01))
b = tf.constant(1.0)
model = tf.matmul(x_t, W) + b
cost_function = tf.reduce_sum(tf.pow((y_t - model),2))
optimizer = tf.train.AdamOptimizer(learning_rate).
minimize(cost_function)
init = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init)
w = W.eval(session = sess)
of = b.eval(session = sess)
print("Before Training ########################
#########################")
print(w,of)
print("#######################################
##########################")
step = 0
previous = 0
while(1):
step = step + 1
sess.run(optimizer, feed_dict={x_t: X_
train.reshape(X_train.shape[0],X_train.
shape[1]), y_t: y_train.reshape(y_
train.shape[0],1)})
cost = sess.run(cost_function, feed_
dict={x_t: X_train.reshape(X_train.
shape[0],X_train.shape[1]), y_t: y_
train.reshape(y_train.shape[0],1)})
107