Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Logistic Regression with a Neural Network mindset python example

import numpy as np
import matplotlib.pyplot as plt
import h5py
import scipy
from PIL import Image
from scipy import ndimage

%matplotlib inline
Comment

Logistic Regression with a Neural Network mindset python example

- 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).

Comment

Logistic Regression with a Neural Network mindset python example

# Loading the data (cat/non-cat)
train_set_x_orig, train_set_y, test_set_x_orig, test_set_y, classes = load_dataset()
Comment

Logistic Regression with a Neural Network mindset python example

y = [1], it's a 'cat' picture.
Comment

Logistic Regression with a Neural Network mindset python example

- m_train (number of training examples)
- m_test (number of test examples)
- num_px (= height = width of a training image)
Comment

Logistic Regression with a Neural Network mindset python example

Number of training examples: m_train = 209
Number of testing examples: m_test = 50
Height/Width of each image: num_px = 64
Each image is of size: (64, 64, 3)
train_set_x shape: (209, 64, 64, 3)
train_set_y shape: (1, 209)
test_set_x shape: (50, 64, 64, 3)
test_set_y shape: (1, 50)
Comment

Logistic Regression with a Neural Network mindset python example

X_flatten = X.reshape(X.shape[0], -1).T      # X.T is the transpose of X
Comment

Logistic Regression with a Neural Network mindset python example

train_set_x_flatten shape: (12288, 209)
train_set_y shape: (1, 209)
test_set_x_flatten shape: (12288, 50)
test_set_y shape: (1, 50)
sanity check after reshaping: [17 31 56 22 33]
Comment

Logistic Regression with a Neural Network mindset python example

train_set_x = train_set_x_flatten/255.
test_set_x = test_set_x_flatten/255.
Comment

Logistic Regression with a Neural Network mindset python example

- Initialize the parameters of the model
- Learn the parameters for the model by minimizing the cost  
- Use the learned parameters to make predictions (on the test set)
- Analyse the results and conclude
Comment

Logistic Regression with a Neural Network mindset python example

print ("sigmoid([0, 2]) = " + str(sigmoid(np.array([0,2]))))
Comment

Logistic Regression with a Neural Network mindset python example

sigmoid([0, 2]) = [ 0.5         0.88079708]
Comment

Logistic Regression with a Neural Network mindset python example

dim = 2
w, b = initialize_with_zeros(dim)
print ("w = " + str(w))
print ("b = " + str(b))
Comment

Logistic Regression with a Neural Network mindset python example

# Example of a picture
index = 25
plt.imshow(train_set_x_orig[index])
print ("y = " + str(train_set_y[:, index]) + ", it's a '" + classes[np.squeeze(train_set_y[:, index])].decode("utf-8") +  "' picture.")
Comment

PREVIOUS NEXT
Code Example
Python :: what should I do when the keras image datagenerato is nit working 
Python :: python: dunder init method 
Python :: como fazer print no python 
Python :: par e impar pygame 
Python :: spooling in os 
Python :: how to check if a list raises IndexError but wihing a if statement python 
Python :: convert math expression as string to int 
Python :: addind scheduling of tasks to pyramid python app 
Python :: python round and map function 
Python :: qtile: latest development version 
Python :: get the hour of every instance of the date_time 
Python :: fetch member by id discord.py 
Python :: sequencia de fibonacci python 
Python :: KivyMD video recording 
Python :: atan of number python 
Python :: Python regex emailadres no jpg 
Python :: filtros en python (no contiene) 
Python :: hi guys 
Python :: python paragraph Pypi 
Python :: how to print multiple lines in one line python 
Python :: check string in a list for substrings and return index 
Python :: multiplication objects 
Python :: pandas within group pairwise distances 
Python :: fill variable based on values of other variables python 
Python :: pd.to_excel header char vertical 
Python :: allowed_hosts error ecs django 
Python :: fill missing values with dict 
Python :: Math Module asin() Function in python 
Python :: copy string x times python 
Python :: empty python 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =