- Apache Spark Deep Learning Cookbook
- Ahmed Sherif Amrith Ravindra
- 97字
- 2025-02-26 11:49:45
How to do it...
This section walks through the steps to create a sigmoid derivative function.
- Just like the sigmoid function, create the derivative of the sigmoid function can with Python using the following script:
def sigmoid_derivative(x):
return sigmoid(x) * (1-sigmoid(x))
- Plot the derivative of the sigmoid function alongside the original sigmoid function using the following script:
plt.figure(figsize=(6, 4), dpi= 75)
plt.axis([-10,10,-0.25,1.2])
plt.grid()
X = np.arange(-10,10,1)
Y = sigmoid(X)
Y_Prime = sigmoid_derivative(X)
c=plt.plot(X, Y, label="Sigmoid",c='b')
d=plt.plot(X, Y_Prime, marker=".", label="Sigmoid Derivative", c='b')
plt.title('Sigmoid vs Sigmoid Derivative')
plt.xlabel('X')
plt.ylabel('Y')
plt.legend()
plt.show()