Skip to content

sujat-khan/deep-learning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Logistic Regression with a Neural Network Mindset

This project is an archived programming assignment from Andrew Ng's Deep Learning Specialization. It demonstrates how to build a logistic regression classifier to recognize cat images, implementing the algorithm from scratch using a "Neural Network mindset."

πŸ“Œ Project Overview

The objective of this notebook is to build a simple image-recognition algorithm that can correctly classify pictures as cat (y=1) or non-cat (y=0).

Instead of relying on high-level machine learning libraries like Scikit-Learn or TensorFlow, this project walks through building the mathematical foundations of logistic regression purely using NumPy. By structuring the code like a neural network (with forward propagation, backward propagation, and parameter updates), it builds intuition for more complex deep learning architectures.

πŸ“‚ Dataset

The project relies on a dataset (data.h5 loaded via lr_utils.py) containing:

  • Training set: m_train images labeled as cat (1) or non-cat (0).
  • Test set: m_test images labeled as cat (1) or non-cat (0).
  • Image Shape: Each image is of shape (64, 64, 3), representing a 64x64 pixel image with 3 color channels (RGB).

During preprocessing, the images are flattened into feature vectors of shape (12288, 1) and standardized by dividing by 255.

πŸ› οΈ Architecture and Key Components

The logistic regression algorithm is structured as a simple 1-layer neural network with a sigmoid activation function.

Mathematical Expression:

For a single example $x^{(i)}$:

  1. Linear combination: $z^{(i)} = w^T x^{(i)} + b$
  2. Activation (Sigmoid): $\hat{y}^{(i)} = a^{(i)} = \sigma(z^{(i)})$
  3. Loss function: $\mathcal{L}(a^{(i)}, y^{(i)}) = - y^{(i)} \log(a^{(i)}) - (1-y^{(i)}) \log(1-a^{(i)})$

The overall Cost Function $J$ is the average of the loss over all training examples.

Implemented Functions:

  • sigmoid(z): Computes the sigmoid activation.
  • initialize_with_zeros(dim): Initializes the weights vector w and bias b to zero.
  • propagate(w, b, X, Y): Performs the forward propagation (computes cost) and backward propagation (computes gradients dw, db).
  • optimize(w, b, X, Y, num_iterations, learning_rate): Updates parameters using Gradient Descent.
  • predict(w, b, X): Predicts labels for given input images using the learned parameters.
  • model(X_train, Y_train, X_test, Y_test): Integrates all the above functions into a unified training pipeline.

πŸ“¦ Dependencies

To run this notebook, the following Python packages are required:

  • numpy: For fundamental matrix/vector operations.
  • h5py: For interacting with the dataset stored in an H5 file.
  • matplotlib: For plotting the cost curve and displaying images.
  • scipy / PIL: For testing the final model with custom images.

πŸš€ Key Takeaways

  • Understanding the shapes and dimensions of data matrices is crucial in deep learning.
  • Vectorization (avoiding for/while loops via NumPy dot products) is heavily utilized to optimize the performance of the algorithm.
  • Logistic Regression can be effectively viewed and implemented as the simplest possible Neural Network.

About

codes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors