Advanced Data Analytics Using Python_ With Machine Learning, Deep Learning and NLP Examples ( 2023)
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Chapter 5
Deep Learning and Neural Networks
W_user = tf.Variable(tf.random_normal([X_train_
user.shape[1],1],stddev=.01))
W_context = tf.Variable(tf.random_normal([X_
train_context.shape[1],1],stddev=.01))
W_out_user = tf.Variable(tf.random_
normal([1,1],stddev=.01))
W_out_context = tf.Variable(tf.random_
normal([1,1],stddev=.01))
model = tf.add(tf.matmul(tf.matmul(x_t_user,
W_user),W_out_user),tf.matmul(tf.matmul(x_t_
context, W_context),W_out_context))
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)
print("Before Training ########################
#########################")
step = 0
previous = 0
cost = 0
while(1):
step = step + 1
if not multilayer:
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)})
109