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 ...

Get Python Machine Learning By Example - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.