
上QQ阅读APP看书,第一时间看更新
How to do it...
This section walks through the steps of creating and plotting a sigmoid function with sample data.
- Create the sigmoid function using a Python function, as seen in the following script:
def sigmoid(input):
return 1/(1+np.exp(-input))
- Create sample x values for the sigmoid curve using the following script:
X = np.arange(-10,10,1)
- Additionally, create sample y values for the sigmoid curve using the following script:
Y = sigmoid(X)
- Plot the x and y values for these points using the following script:
plt.figure(figsize=(6, 4), dpi= 75)
plt.axis([-10,10,-0.25,1.2])
plt.grid()
plt.plot(X,Y)
plt.title('Sigmoid Function')
plt.show()