Use a Numpy Logistic Regression neural network to predict on dog and cat images

6 min readNov 15, 2023

While there are machine learning and deep learning libraries, it is always a good idea to have an understanding of how the models are developed in order to enhance the student’s understanding of data science. In this blog post, therefore, I intend to discuss how to create a numpy logistic regression neural network in order to classify dog and cat images. In order to accomplish this task, I have used some of the code from grantgasser’s Github account. I would like to add, however, that the code required modifications before I could get it to work.

I have used Kaggle’s mini cats and dogs dataset on this project, and it can be obtained here:-

Logistic regression is a binary classification method. It can be modelled as a function that can take in any number of inputs and constrain the output to be between 0 and 1. This means, we can think of Logistic Regression as a one-layer neural network.

I have obtained the code for a numpy logistic regression neural network and have used it to write a program in Kaggle’s neural network, storing it in my account for that data science company.

The first thing that I did was to import the libraries that I would need to execute the program, being:-

  1. Numpy to create numpy arrays and perform numerical computations,
  2. Random to generate random numbers,
  3. PIL to process images,
  4. Cv2 to process images,
  5. Glob to process files,
  6. Shutil to process files, and
  7. Matplotlib to visualise the images.

I used the os library to retrieve all of the files that are in the input directory for this dataset:-

I then visualised one of each cat and dog image:-




I have close to five decades experience in the world of work, being in fast food, the military, business, non-profits, and the healthcare sector.