Giter VIP home page Giter VIP logo

logistic-regression-classifier's Introduction

Simple Logistic Regression Classifier in Python

The code builds from scratch an image-recognition algorithm that can classify pictures as cat or non-cat with about 70% accuracy. The model is simple, it mimics a Neural Network of 2 layers, with a single hidden layer (Logistic Regression is actually a very simple Neural Network), and it easily overfits the training data. No regularization is provided in this solution. The hyperparameters have values, as it is given below:

  • learning rate: 0.01
  • number of iterrations: 2000

The files are organized as follows:

  • Logistic_Regression_Utils.py - contains utility functions for loading and preprocessing the datasets. The hdf5 files "datasets/train.h5" and "datasets/test.h5" contain the training and test sets of images. The function load_dataset() returns the train and test datasets, as well as the list of classes ("cat", "non-cat"). Each line of the train and test datasets is an array representing an image. Each image is of shape (number_of_pixels, number_of_pixels, 3) where 3 is for the three RGB channels. The function process_dataset() first reshapes the datasets (the images are flattened into single vectors of shape (num_px * num_px * 3, 1)), and then centers and standardizes them (in this case it is enough to divide every row of the dataset by 255 - the maximum value of a pixel channel)

  • Logistic_Regression_Classifier.py - contains functions for parameter initialization and computing the sigmoid function, implementation of forward and backward propagation (computes the cost function and its gradient), implementation of the gradient descent algorithm to optimize the weights and bias (update the parameters), compute predictions (use the learned parameters to predict the labels for a given set of excamples). At the end, all functions are merged into a single model function.

  • Learn_the_Model.py - loads the datasets, learns the model and stores the learned parameters into an hdf5 file.

  • Logistic_Regression_Test.py - test with your own image. Run the code and check if the algorithm has made the right prediction.

We can examine different choices of the learning rate and number of iterrations to try to achieve better performance. Rerun the file Learn_the_model.py to see the results.

logistic-regression-classifier's People

Contributors

malinova avatar

Watchers

 avatar

Forkers

samarpreet89

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.