📘 Lesson · Lesson 90
Activation Functions
What is an Activation Function?
💡 At a Glance
An activation function decides whether a neuron "fires". It adds non-linearity so neural networks can learn complex patterns.
Common Functions
| Function | Output Range | Use |
|---|---|---|
| Sigmoid | 0 to 1 | binary output / probabilities |
| Tanh | -1 to 1 | hidden layers (zero-centered) |
| ReLU | 0 to infinity | most common in deep networks |
In Code
Python
import numpy as np def relu(x): return np.maximum(0, x) def sigmoid(x): return 1 / (1 + np.exp(-x)) print(relu(-3), relu(5)) # 0 5 print(round(sigmoid(0), 2)) # 0.5
0 5
0.5
Summary
- Activation functions add non-linearity to neural networks.
- ReLU is most common; Sigmoid for probabilities; Tanh is zero-centered.
💻 Live Code Editor
This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.