Giter Site home page Giter Site logo

saritmukherjee / logistic_regression_numpy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wladiarce/logistic_regression_numpy

0.0 1.0 0.0 82 KB

A logistic regressor class written in python, with the testing code against an example dataset.

Jupyter Notebook 100.00%

logistic_regression_numpy's Introduction

Logistic regression using numpy

Learning method: mini-batch gradient descent


Quick intro to logistic regression

Logistic regression can be used for categorical classification. In our case, we will focus on a model of binary classification.

To do that, a logistic / sigmoid function will be fitted to the data. This function tends to 1 as z -> infinite and to 0 as z -> -infinite, and is as follows:

To obtain a 0 or 1 output, one just simply sets a threshold at 0.5: everything below is zero and everything above is one.

Having a dataset with a series of samples, each of those with their given features, we can express z in matrix form as follows:

Where X is the matrix of [samples] rows and [features] columns, and theta is the vector of the model parameters (weights of our regressor).

The objective will be to obtain that theta vector given a set of X and y([0,1]), that best fits the data. How? Minimizing the cost function of the problem.

The cost function J of a logistic regression problem is the following:

To find the theta that minimizes the error between the predicted and the real data, an iterative process where that cost function is derived to find its minimum and update the theta parameters to go towards it will be applied. This is called gradient descent:

with

Different ways to update the parameter in function of the gradient can be applied (once for every data entry, once for all the dataset...). In this case, it has been decided to do it in small batches, thus we will be appliying minibatch gradient descent.


Tested with the Breast Cancer Wisconsin (Diagnostic) Data Set, included in sklearn

  • For each cell nucleus 10 different features are stated (radius, texture, area, compactness...)
  • For each feature three values appear: mean, error and worst
  • This leads to a 30 dimensional classification problem, into two categories: benign or malignant cell

logistic_regression_numpy's People

Contributors

wladiarce avatar

Watchers

 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.