Giter VIP home page Giter VIP logo

cagriguerbuez / logistic-regression-from-scratch-using-numpy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from trishlam/logistic-regression-from-scratch-using-numpy

0.0 0.0 0.0 46 KB

In this repository, the PIMA Indians diabetes dataset has been used to illustrate how to create a logistic regression model from scratch using gradient descent algorithm with the intuition of neural network.

Jupyter Notebook 100.00%

logistic-regression-from-scratch-using-numpy's Introduction

Logistic-regression-from-scratch-using-NumPy

In this repository, the PIMA Indians diabetes dataset has been used to illustrate how to create a logistic regression model from scratch using vectorization of the predictor variables and gradient descent algorithm for cost minimization with the intuition of neural network. The steps used to create the model are listed below -

1. Defining the activation function

The model algorithm consists of linear transformation of predictor variables to predict the output, which will give a numeric value. Thus, to restrict those values in the range of 0 and 1, an activation function is used here. We have used the sigmoid activation function here which is given by-

sigmoid(Z)=1/(1+e^(-Z))

2. Random initialization of parameters (bias term and coefficients)

The parameters 'w' and 'b' have been initialized as 0 to start with. With each iteration of the logistic regression algorithm, the values are updated using the optimization function.The 'w' vector has the shape (no. of features in predictor, 1).

3. Forward propagation

In this step, we do the activation conversion and compute the cost of the model which is given by image

4. Optimization

Using this function definition, we optimize the cost function mentioned above and update the parameters to minimize the cost. The gradients descent algorithm is used and using the algorithm, the gradients of the 'w' and 'b' parameters are computed and the parameters are updated by using the following formula-

w := w - learning_rate * dw, and
b := b - learning_rate * db

By running this function using loop for n no. of iterations, we reach a convergence point where the cost function doesn't decrease any further. Another important thing to note is the choice of learning rate. Learning rate shouldn't be too small to increase the computational expense, or too large to overshoot the global minima. Thus, we try the model algorithm with various learning rates to find out the rate which gives optimizes the cost function the best.

The final step is to create a 'predict' function and calculate the accuracy of predicted alues from test set.

logistic-regression-from-scratch-using-numpy's People

Contributors

trishlam avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.