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

List of Computer Vision APIs

Computer Vision APIs Different computer vision tools and APIs are : Google CV Watson VR Amazon R Microsoft CV Clarif.ai Cloudsight Scale https://www.scaleapi.com/image-annotation Imagga vize.ai https://vize.ai/ http://www.recognize.im/ Moodstocks ( http://www.moodstocks.com/pricing/ ) * Kooaba ( http://www.kooaba.com/en/plans_a... ) * IQ Engines ( https://www.iqengines.com/pricing/ ) * LTU technologies ( http://www.ltutech.com/ ) Camfind - Image recognition back-end for the popular app CamFind. Take advantage of the leading image recognition platform through an easy to use web API. Recognize API | Mashape - Vufind Recognize is a real-time image recognition API for classification and monetization of photos and videos. Recognize uses object recognition to uncover meaning and metadata of photos and videos for contextual image commerce and advertising. Kooaba - Our cloud-based image recognition solutions mak...

Cat Vs Dog Classification Using TensorFlow CNN

This code is copy of - https://www.kaggle.com/sentdex/full-classification-example-with-convnet/notebook - work.  I have tried this code and executed successfully. Description: The data set (training and test) are taken from Kaggle Dog vs Cat competition.  https://www.kaggle.com/c/dogs-vs-cats-redux-kernels-edition/data In this the training data is encoded into an array containing the feature of each image plus its corresponding label. Functions used for this are : label_img() and create_training_data() . Similarly preprocessing is done for test data set also. The test data set images are stored as numpy array with its corresponding IDs. Function used is :process_test_data Numpy is used for preprocessing the image data into arrays. Using Tensorflow '- tflearn a DNN model is created. Here it has six convolutional layers followed by maxpool layers . Activation function used is 'RELU'. Then One fully connected layer with drop out and then softmax regression is also ...