Learn practical skills, build real-world projects, and advance your career

Logistic Regression with a Neural Network mindset

Welcome to your first (required) programming assignment! You will build a logistic regression classifier to recognize cats. This assignment will step you through how to do this with a Neural Network mindset, and so will also hone your intuitions about deep learning.

Instructions:

  • Do not use loops (for/while) in your code, unless the instructions explicitly ask you to do so.

You will learn to:

  • Build the general architecture of a learning algorithm, including:
    • Initializing parameters
    • Calculating the cost function and its gradient
    • Using an optimization algorithm (gradient descent)
  • Gather all three functions above into a main model function, in the right order.

Updates

This notebook has been updated over the past few months. The prior version was named "v5", and the current versionis now named '6a'

If you were working on a previous version:
  • You can find your prior work by looking in the file directory for the older files (named by version name).
  • To view the file directory, click on the "Coursera" icon in the top left corner of this notebook.
  • Please copy your work from the older versions to the new version, in order to submit your work for grading.
List of Updates
  • Forward propagation formula, indexing now starts at 1 instead of 0.
  • Optimization function comment now says "print cost every 100 training iterations" instead of "examples".
  • Fixed grammar in the comments.
  • Y_prediction_test variable name is used consistently.
  • Plot's axis label now says "iterations (hundred)" instead of "iterations".
  • When testing the model, the test image is normalized by dividing by 255.

1 - Packages

First, let's run the cell below to import all the packages that you will need during this assignment.

  • numpy is the fundamental package for scientific computing with Python.
  • h5py is a common package to interact with a dataset that is stored on an H5 file.
  • matplotlib is a famous library to plot graphs in Python.
  • PIL and scipy are used here to test your model with your own picture at the end.
import numpy as np
import matplotlib.pyplot as plt
import h5py
import scipy
from PIL import Image
from scipy import ndimage
from lr_utils import load_dataset

%matplotlib inline

2 - Overview of the Problem set

Problem Statement: You are given a dataset ("data.h5") containing:
- a training set of m_train images labeled as cat (y=1) or non-cat (y=0)
- a test set of m_test images labeled as cat or non-cat
- each image is of shape (num_px, num_px, 3) where 3 is for the 3 channels (RGB). Thus, each image is square (height = num_px) and (width = num_px).

You will build a simple image-recognition algorithm that can correctly classify pictures as cat or non-cat.

Let's get more familiar with the dataset. Load the data by running the following code.