Skip to main content

Implement Logistic Regression In neural Nets (From Basics)

Here I will show you how to implement a neural network for logistic regression from basics.

What is logistic regression ?
The two main types of problems in the machine learning are are classification and regression. Both techniques are used for prediction of labels for a given data set. In classification, data can be fitted into a different classes, hence the labels will give discrete values. For regression, the data set is mapped into continuous values. Different types of regression include linear regression, logistic regression etc. 

Here for one training example, the neural network using logistic regression is explained. If two features of a image is considered for training purpose , the linear combination of the features with weights and bias can be shown as below :
Z = w1x1+w2x2+b
The activation function selected for logistic regression here is sigmoid function.
This shows the forward propagation step in neural net. Now the output of this neural net should be close to the actual output for the data. Hence first calculate the loss function for the training example as :
L(a,y)
where 'a' is current output and 'y' is actual label.
For all training examples m, consider the cost function of neural net as J(w,b)
Hence for a good model, optimization is applied for this cost function.
Gradient Descent can be used for optimization. After this weight 'w' can be updated as :
w = w- (learning rate) * dw
b = b- (learning rate) * db


The above figure gives an overall idea about the procees in logistic regression implemented on neural network.


The main equations for our neural network is shown in the above image.
In the next image we will see how to derive the
* w = w- (learning rate) * dw
* b = b- (learning rate) * db
 using calculus.

Hence a simple neural network is explained for logistic regression.

Comments

Popular posts from this blog

Converting DICOM images into JPG Format in Centos

Converting DICOM images into JPG Format in Centos I wanted to work with medical image classification using Deep learning. The Image data set was .dcm format. So to convert the images to jpg format following steps have performed. Used ImageMagick software. http://www.ofzenandcomputing.com/batch-convert-image-formats-imagemagick/ Installed ImageMagick in Centos by downloading the rom and installing its libraries : rpm -Uvh ImageMagick-libs-7.0.7-10.x86_64.rpm rpm -Uvh ImageMagick-7.0.7-10.x86_64.rpm After installation the the image which is to be converted is pointed in directory. Inside the directory executed the command: mogrify -format jpg *.dcm Now dcm image is converted to JPG format. 

TensorFlow for Beginners

TensorFlow - Image Recognition for New Data Set Tensorflow is an open source machine learning tool provided by Google. It provides various machine learning solutions. Most prominent use for Tensorflow is Computer vision. Here is a small post, about how you can do tensorflow training on your new image data set using python. First Install tensorflow in your system using following command (using python pip) sudo apt-get install python-pip python-dev #used for python 2.7 Then download the TensorFlow Inception model folder from https://github.com/tensorflow/models/tree/master/inception Save your new Image data under a folder named Images.. Inside the folder group each class of images into each separate folder(with corresponding names) Then change flowers_data.py in inception model according to your new data set Places to change:   def num_classes(self):     """Returns the number of classes in the data set."""     re...