Week 3 practice lab default code keeps shwoing error


THIS A DEFAULT CODE ALREADY PRESENT IN NOTEBOOK. BUT AS I RUN IT, IT KEEPS SHOWING ERROR DUE TO WHICH I CANT PROGRESS FURTHER IN ASSSIGNMENT
PROBLEMATIC CODE:
print ("sigmoid([ -1, 0, 1, 2]) = " + str(sigmoid(np.array([-1, 0, 1, 2]))))

UNIT TESTS

from public_tests import *
sigmoid_test(sigmoid)

ERROR IT SHOWS:
sigmoid([ -1, 0, 1, 2]) = [3.71828183 2. 1.36787944 1.13533528]

AssertionError Traceback (most recent call last)
in
3 # UNIT TESTS
4 from public_tests import *
----> 5 sigmoid_test(sigmoid)

~/work/public_tests.py in sigmoid_test(target)
3
4 def sigmoid_test(target):
----> 5 assert np.isclose(target(3.0), 0.9525741268224334), “Failed for scalar input”
6 assert np.allclose(target(np.array([2.5, 0])), [0.92414182, 0.5]), “Failed for 1D array”
7 assert np.allclose(target(np.array([[2.5, -2.5], [0, 1]])),

AssertionError: Failed for scalar input

Hi, @Vaibhavkalsotra

Please, check your implementation in the function sigmoid as it should return a scaler value (a single number) if its input is a scaler value. and an array if the input is a list or array.

recall that the sigmoid function is [\displaystyle S(z) = \frac{1}{1 + e^{-z}}]

Best regards,
Moaz

i still cant get it because in assignment i had to write only the sigmoid formula.Rest all was default given. I am not getting it how to rectify this error

If we look at this part of your screenshot

Screenshot from 2022-11-07 13-19-22

it says your sigmoid computes sigmoid(0) = 2 which is incorrect. sigmoid(0) should equal to 0.5. This means you have not yet implemented the function correctly. Remember to sum all the terms in the denominator first, before dividing 1 with the sum.

Raymond

1 Like

1 Like

thank you i got it
thanks for the advice