Getting started with the logistic function

Let's start with an introduction to the logistic function (which is more commonly referred to as the sigmoid function) as the algorithm core before we dive into the algorithm itself. It basically maps an input to an output of a value between 0 and 1, and is defined as follows:

We can visualize what it looks like by performing the following steps:

  1. Define the logistic function:
>>> import numpy as np
>>> def sigmoid(input):
... return 1.0 / (1 + np.exp(-input))
  1. Input variables from -8 to 8, and the corresponding output, as follows:
>>> z = np.linspace(-8, 8, 1000)
>>> y = sigmoid(z)
>>> import matplotlib.pyplot as plt
>>> plt.plot(z, y)
>>> plt.axhline(y=0, ls='dotted', color='k')
>>> plt.axhline(y=0.5, ls='dotted', color='k')
>>> plt.axhline(y=1, ls='dotted', color='k')
>>> plt.yticks([0.0, 0.25, 0.5, 0.75, 1.0])
>>> plt.xlabel('z')
>>> plt.ylabel('y(z)')
>>> plt.show()

Refer to the following screenshot for the end result:

In the S-shaped curve, all inputs are transformed into the range from 0 to 1. For positive inputs, a greater value results in an output closer to 1; for negative inputs, a smaller value generates an output closer to 0; when the input is 0, the output is the midpoint, 0.5.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.163.62