In machine learning, we often need to squash an input value into a range between 0 and 1 (representing a probability). To do this, we use the Sigmoid Activation Function.
Mathematically, it transforms any real number into an “S-shaped” curve defined by:
$$
\sigma(x) = \frac{1}{1 + e^{-x}}
$$
Here is how you can implement it simply in Python:
import numpy as np
def sigmoid(x):
# Apply the sigmoid formula
return 1 / (1 + np.exp(-x))
print(sigmoid(0)) # Output: 0.5
It’s elegant,