<jupyter_start><jupyter_text>Logistic Regression It is a classification algorithm, here we will be seeing binomial logisitc Regression which labels the data set into two categories.theta = x * weight + biasy = sigmoid(theta)sigmoid is a function which is use to breakdown theta into two categoriessigmoid(x) = 1 / (1 + e -x)  Creating Data Let's create some data, with some random weights and bias, and then we will be using our logistic model to retrieve this weight and bias<jupyter_code>import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
import seaborn as sns
import os
'''
    we will be creating sigmoid function here

'''

def sigmoid(x):
    """
        return the value between 0 and 1.
    """
    
    return 1 / (1 + np.exp(-x))
np.random.seed(42)

x_data = np.random.randn(2000,10) #2000  X 10 dimensions
weight_orig = np.random.randn(1,10) #weight of dimensions 1 X 10 (ROW VECTOR)
bias_orig = -0.2

theta = np.matmul(x_data, weight_orig.T) + bias_orig

y_probability = sigmoid(theta)

y_data = np.random.binomial(1,y_probability) #binomial distribution convert the y_probability to 0 and 1.<jupyter_output><empty_output><jupyter_text>Building a Model<jupyter_code>g = tf.Graph()

with g.as_default():
    x = tf.placeholder(dtype = tf.float32, shape = [None,10])
    y = tf.placeholder(dtype = tf.float32, shape = None)
    
    with tf.name_scope('inference') as scope:
        """
        
            Here we will be assigning some random weight and biases.
            
        """
        
        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
        
    with tf.name_scope('loss') as scope:
        """
            LOSS FUNCTION 
            
            For logistic regression, loss function is
            
            - y * log(y_pred) + (1-y) * log(1-y_pred)
            
            we will be using inbuild tensorflow loss function for logistic regression
            
            tf.nn.sigmoid_cross_entropy_with_logits(labels = true_y, logits = pred_y)
        
        """
        
        loss = tf.nn.sigmoid_cross_entropy_with_logits(labels = y, logits = y_pred)
        loss = tf.reduce_mean(loss) #cost function
        
    with tf.name_scope('train') as scope:
        learning_rate = 0.2
        optimizer = tf.train.GradientDescentOptimizer(learning_rate)
        train = optimizer.minimize(loss)
        
    init = tf.global_variables_initializer()
    with tf.Session() as sess:
        sess.run(init)
        
        for i in range(1000):
            _,l= sess.run([train,loss],{x:x_data,y:y_data})
            w, b = sess.run([weight,bias])
            print(f'-----------------------------{i}---------------------------------------')
            print('weight',w)
            print('bias',b)
            print(f'loss {l * 100}%')
weight_orig
bias_orig<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12263838249917136, 'fraction_numerical': 0.018561484918793503, 'mean_word_length': 2.2983606557377048, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '252106', 'license': 'MIT', 'n_tokens_mistral': 994, 'n_tokens_neox': 939, 'n_words': 261, 'path': 'Logistic Regression.ipynb', 'repo_name': 'rishav-ish/DeepLearningTutorial', 'size': '3017'}