Project - Building Cat vs Non-Cat Image Classifier using NumPy and ANN

24 / 32

Cat vs Non-cat Classifier - Defining some utility functions - Predict

This function predicts the labels of the dataset by calling the sigmoid function.

The prediction for a sample is given out as

  • 1 if the sigmoid function returns a value greater than 0.5
  • 0 if the sigmoid function returns a value lesser than 0.5

Copy-paste the following code to predict.

def predict(w, b, X):
    m = X.shape[1]
    Y_prediction = np.zeros((1, m))
    w = w.reshape(X.shape[0], 1)

    #Compute probability vector
    A = sigmoid(, X) + b)

    for i in range(A.shape[1]):
        Y_prediction[0, i] = 1 if A[0, i] > 0.5 else 0

    return Y_prediction
Get Hint See Answer

Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...