<jupyter_start><jupyter_text>Linear Regression We will be making a simple linear regression model using tensor flow.Linear Regression models are used to show or predict the relationship between two variables or factors.The Simple regression model is represented by:y = bias + weight * x  Create dataBefore implementing the simple linear regression model let's first create out data.<jupyter_code>import numpy as np
import tensorflow as tf
import os
x_data = np.random.randn(2000,10)   #2000 rows and 10 columns
w = np.random.randn(1,10)      #assigning weight vector
b = -0.8                         #any random bias

#calculating our y_data or true y

y_data = np.matmul(x_data,w.T) + biased     #it will gives values in a shape 2000 X 1<jupyter_output><empty_output><jupyter_text>Implementing ModelNow here we will be creating our model using tensor flow, we will be using placeholder, variable, session and Gradient Descent optimizer for creating our models.<jupyter_code>epoch = 20              #epoch is the number of iteration for which you want to train our model and optimize it.

g = tf.Graph()          #creating a new tensor flow graph.

with g.as_default():    #making g as a default graph
    x = tf.placeholder(tf.float32,shape = [None,10])  #creating a placeholder for our x_data
    y_true  = tf.placeholder(tf.float32, shape = None)# creating a placeholder for our y_data
    
    '''
        INFERENCE
        
        Here we will assign our weight and bias randomly, right now we will be using zero.
        Will calculate using y using the weight, bias and x.
    
    
        For assigning weight and bias will be using tensor flow variable since it needed to get updated at every steps.
        when we using loss function and doing back propogation to optimize our model.
        
    '''
    
    with tf.name_scope('inference') as scope:
        weight = tf.Variable(np.zeros((1,10)),dtype = tf.float32, name = 'weight') 
        bias   = tf.Variable(0, dtype = tf.float32, name = 'bias')
        
        y_pred = tf.matmul(x,tf.transpose(weight)) + bias  #calculating y for given weight and bias and x.
        
    '''
        LOSS FUNCTION
        
        This is use to find the difference between predicted value and exact values.
        
        using loss function we optimize our model by minimizing the value of loss function i.e difference between
        predicted value and exact values.
        
        There are various loss function availabe here we will be using MSE (Mean Squared Error).
        
        MSE
        In MSE we take the square of differences between exact and predicted values and take mean of it.
    
    
    '''
    
    with tf.name_scope('loss') as scope:
        loss = tf.reduce_mean(tf.square(y_pred - y_true)) #MSE, implemented using tf functions.
        
    '''
        TRAINING AND OPTIMIZATION
        
        Here we will train our model and optimize it using Gradient Descent Optimization
        
        GRADIENT DESCENT OPTIMIZATION
        
        It is a way of differentiating cost function, and taking minimum value out of it. you can learn about it more.
    
    '''
    
    with tf.name_scope('train') as scope:
        learning_rate = 0.2 #assigning learning rate, it is the rate at which you want your model to learn. READ ABOUT GDO
        optimizer = tf.train.GradientDescentOptimizer(learning_rate)
        train = optimizer.minimize(loss)
        
    #Executing out model
    
    with tf.Session() as sess:
        init = tf.global_variables_initializer() #initializing our variables
        sess.run(init)
        for step in range(epoch):
            sess.run(train,{x:x_data, y_true : y_data})
            w, b = sess.run([weight,bias]) #tuple unpacking
            print('-------------------------',step,'--------------------------------------')
            print('weight',w)
            print('bias',b)
        
        '''
            Here we will be saving our session graph so that we can see it using tensorboard
            we do it using tf.summary.FileWriter(path,graph)
            
            Go to cmd to the folder where your graph will be save and enter this command
            
            tensorboard --logdir foldername
            
            The link will be popout, paste that url to browser to see the skeletion of our graph.
            
        '''
        
        path = os.getcwd() #getting our current working directory.
        
        path += '\\Graph'
        
        File_writer = tf.summary.FileWriter(path,sess.graph) #it will create logg directory for your session graph<jupyter_output>------------------------- 0 --------------------------------------
weight [[ 0.02981151  0.43139172  0.53622156 -0.36803475 -0.9189421   0.1092513
  -0.37622112  0.06575792 -0.3299995  -0.16880251]]
bias -0.33350325
------------------------- 1 --------------------------------------
weight [[ 0.04132396  0.67929226  0.8388109  -0.5867117  -1.4885838   0.15546077
  -0.6037308   0.10365273 -0.5271901  -0.25681317]]
bias -0.528571
------------------------- 2 --------------------------------------
weight [[ 0.04393287  0.8216894   1.0090469  -0.7174615  -1.8421837   0.1722578
  -0.74117893  0.12538373 -0.6453503  -0.3022191 ]]
bias -0.64248335
------------------------- 3 --------------------------------------
weight [[ 0.04262934  0.9034336   1.1044489  -0.7961169  -2.0619924   0.1761771
  -0.8241468   0.13779421 -0.7163258  -0.32534   ]]
bias -0.7088765
------------------------- 4 --------------------------------------
weight [[ 0.03994764  0.9503193   1.1576467  -0.84371233 -2.1988344   0[...]<jupyter_text>our original bias and variables are<jupyter_code>print(w,b)<jupyter_output>[[ 0.02700739  1.0127822   1.2215573  -0.9190953  -2.4267988   0.16270512
  -0.94987655  0.15415025 -0.82417846 -0.3472376 ]] -0.8000069
{'fraction_non_alphanumeric': 0.13600682593856656, 'fraction_numerical': 0.09368600682593857, 'mean_word_length': 1.926110833749376, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '481647', 'license': 'MIT', 'n_tokens_mistral': 2008, 'n_tokens_neox': 1691, 'n_words': 598, 'path': 'LinearRegressionTutorial.ipynb', 'repo_name': 'rishav-ish/DeepLearningTutorial', 'size': '5860'}