Posts

Showing posts from 2019

Tensorflow - Simplest Gradient Descent using GradientDescentOptimizer

Below is the code to find the minimum possible value of weight (w) such that the outcome of equation is closest to 0, using Gradient Descent method. These weights are multiplied with input (x) to compute cost, thus minimizing it. The equation is below... w 2 - 10 w + 25 ---------------------- (i) i.e. ( w - 5 ) 2 Thus, the coefficients from (i) would be 1, -10 and 25 import numpy as np import tensorflow as tf coefficients = np.array([[ 1 ], [ - 10 ], [ 25 ]]) # try 1, -20, 100 -- line 4 w = tf.Variable([ 0 ], dtype = tf.float32) x = tf.placeholder(tf.float32, [ 3 , 1 ]) cost = (x[ 0 ][ 0 ] * w ** 2 ) + (x[ 1 ][ 0 ] * w) + x[ 2 ][ 0 ] # (w-5)^2 train = tf.train.GradientDescentOptimizer( 0.01 ).minimize(cost) init = tf.global_variables_initializer() with tf.Session() as session: session.run(init) print (session.run(w)) for i in range ( 1000 ): session.run(train, feed_dict = {x:coefficients}) print (session.run(w)) T

Baseline: Data, ML, AI https://www.qwiklabs.com/quests/34 - Tips

Baseline: Data, ML, AI https://www.qwiklabs.com/quests/34 Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab , shows how long Cloud resources will be made available to you. What you need Access to a standard internet browser (Chrome browser recommended). Dataprep : Qwik Start - GSP105 only runs on Chrome Time to complete the lab without pause Tips:   Open the tabs in separate windows, side-by-side . Accept the terms and conditions. Do NOT add recovery options or two-factor authentication (because this is a temporary account). Do NOT sign up for free trials. All the best with the quest!