<jupyter_start><jupyter_text>Some Basic terms in Tensorflow* `Variable`: Something that was able to __vary__ data, and that can __updated__ in any point of time* `constant`: Something that can __not__ be change after initialization* `placeholder`: A __promise__ to provide value later<jupyter_code># parameters

w = tf.Variable(0.3, tf.float32, name = "weight")
b = tf.Variable(-0.3, tf.float32, name = "bias")

# inputs and outputs

x = tf.placeholder(tf.float32, name="input")
y = tf.placeholder(tf.float32, name="output")

# Basic linear Model

linear_model = (w * x) + b<jupyter_output><empty_output><jupyter_text>Build the computational Graph and Run itIn tensorflow `Variables`, `constant`, `placeholder` doesn't hold anything except the structure of it, until it `run` in a `Session`. When we initialize a `Variable`, `constant` or a `placeholder` it's just creates a computational graph. Nothing happens until a `Session` being Start. The acutal works done with a Tensorflow `Session`.<jupyter_code># initialize the variable with global_variables_initializer()

init = tf.global_variables_initializer()<jupyter_output><empty_output><jupyter_text>The mathematical formula behind loss function:\begin{equation}J(\theta_0, \theta_1) = \frac{1}{2m} \sum(h_\theta x^i - y^i)^2\end{equation}here,* $h_\theta x^i$ is the hypotheis or in other words is the prediction we made* $ y^i $ is the actual output* m is the number of trainning examples<jupyter_code># Calculating loss/ loss function

squared_delta = tf.square(linear_model - y)
loss = tf.reduce_sum(squared_delta)
# x and y are placeholder and we promise to provide value later, Now this was the time when we provide the values.

with tf.Session() as sess:
    sess.run(init)
    print(sess.run(loss, {x:[1,2,3,4], y:[0,-1,-2,-3]}))<jupyter_output>23.66<jupyter_text>__So here we see that we have a loss of: `23.66`__ Now we need to reduce the loss using a OptimizerAn `Optimizer` is used for reduce the `loss`. `Optimizier` looks the changes of loss by updating/changing the Variable in any (forward/postive or backward/negative) direction. If it see that changes in postive direction will increase the loss then it will try to update the variable in negative direction. The main goal of a `Optimizer` is to reduce the `loss`.<jupyter_code># Reducing the Loss using Gradient Descent Optimizer with a 0.01 learning rate
# learning rate is nothing but the steps, number of steps the Variable will update by the Optimizer

optimizer = tf.train.GradientDescentOptimizer(0.01) 
train = optimizer.minimize(loss)

# After all structure are defined its time to run the computation graph into a Session

with tf.Session() as sess:
    sess.run(init)
    for i in range(1000):
        sess.run(train, {x:[1,2,3,4], y:[0,-1,-2,-3]})
        
    print("Updated weight and bias to reduce the loss upto 100%\n",sess.run([w,b]))<jupyter_output>Updated weight and bias to reduce the loss upto 100%
 [-0.9999969, 0.9999908]<jupyter_text>* updated weight ~= -1  and* updated bias ~= 1according to the result, if we update the `weight` from `0.3` to `-1` and `bias` from `-0.3` to `1` the approximate `error/loss` will be `0`  Lets Validating the optimizer result:```inputs  =>  x:[1,2,3,4]outputs =>  y:[0,-1,-2,-3]weight  => -1bias    =>  1```for `x = 1`,\begin{equation}linearModel = (w * x) +b\\= (-1 * 1 + 1)\\= 0\end{equation}so, for x = 1 the y = 0 is correct.for `x = 2`,\begin{equation}linearModel = (-1 * 2 + 1)\\= -1\end{equation}for `x = 3`,\begin{equation}linearModel = (-1 * 3 + 1)\\= -2\end{equation}for `x = 4`,\begin{equation}linearModel = (-1 * 4 + 1)\\= -3\end{equation}  Hence, we can say that the `Optimizer` result is correct. __For Visualizing a Tensorflow Graph we have tensorboard: Let us see how to use it:__<jupyter_code>with tf.Session() as sess:
    sess.run(init)
    for i in range(1000):
        sess.run(train, {x:[1,2,3,4], y:[0,-1,-2,-3]})
    
    File_Writer = tf.summary.FileWriter("tensorboard_output", sess.graph)
    print("Updated weight and bias to reduce the loss upto 100%\n",sess.run([w,b]))<jupyter_output>Updated weight and bias to reduce the loss upto 100%
 [-0.9999969, 0.9999908]
{'fraction_non_alphanumeric': 0.12583892617449666, 'fraction_numerical': 0.03547459252157239, 'mean_word_length': 4.586345381526105, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '102502', 'license': 'MIT', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1354, 'n_words': 494, 'path': 'Introduction to Tensorflow/A very first introduction with Tensorflow.ipynb', 'repo_name': '78526Nasir/Kaggle-Students-Academic-Performance', 'size': '4172'}