Contents
Deep Breakdown
What it tells me (Situation Awareness): is Euler's number, the base of the natural logarithm. It is arguably the most important constant in data science after . You encounter it in the exponential function , in the sigmoid/softmax activation functions, in the Poisson and Gaussian distributions, in the natural logarithm , and in any model or formula involving continuous growth, decay, or probability. If you do ML without knowing , you are driving blind.
Flowchart
Real-world use
Where it is used
Anywhere continuous growth or decay appears: compound interest, population growth, radioactive decay, probability distributions (normal, Poisson, exponential), activation functions in neural networks (sigmoid, softmax), and loss functions (cross-entropy, log-loss).
Problem it solves
Many natural processes grow or decay at a rate proportional to their current size. The mathematical description of this behavior, , has the solution . The constant is the only base for which the exponential function is its own derivative. This "self-referential" derivative property makes the natural choice for describing change in continuous time and for simplifying calculus.
How it solves the problem
Because , the exponential function with base has the cleanest possible calculus. Derivatives and integrals of do not generate messy scaling factors. This is why probability densities, loss function gradients, and statistical proofs all simplify when expressed in terms of .
Example in a business
The logistic (sigmoid) function used in binary classification: . This converts a raw score into a probability between 0 and 1. Without , this transformation does not exist in the clean form that makes gradient descent tractable.
The formula, piece by piece
Breaking the definition:
- : a mathematical constant, named after Leonhard Euler (1707-1783), though Euler did not discover it (Jacob Bernoulli found it while studying compound interest).
- : limit. The value approached as a parameter grows without bound.
- : increases indefinitely.
- : the compound interest formula with compounding periods.
- The full definition: Alternative series definition (equivalent): Key property: .
The exponential function is its own derivative. This is the defining characteristic of . Logarithm connection: , , .
The formula in words
" is the limit of as grows to infinity. Think of it this way: if you start with $\$1$and earn$100%xe \approx $2.72e = 1 + 1 + \frac{1}{2!} + \frac{1}{3!} + \frac{1}{4!} + \cdots$. Each term adds a smaller piece. The sum converges to $e$.
Critical Concepts
- e is irrational and transcendental: like , its decimal expansion never terminates or repeats, and it is not the root of any polynomial with integer coefficients.
- The natural exponential: is the unique function that equals its own derivative. This is why it appears in every differential equation describing natural growth/decay.
- Natural logarithm: . In code:
math.log(x)in Python (no base = natural log),log(x)in R (also natural log by default). Do not confuse withlog10(x). - Sigmoid function: . Used in logistic regression and neural network output layers for binary classification. Maps any real number to .
- Softmax: generalization of sigmoid for multi-class: . Converts a vector of scores into a probability distribution.
- Cross-entropy loss: .
The (natural log, base ) appears because information theory is built on .
Step-by-step calculation (tiny example)
Task: compute using the first 5 terms of the series .
Step 1: List the first 5 terms
- :
- :
- :
- :
- :
Step 2: Sum the terms
Step 3: Compare to the true value True . Our 5-term estimate gives . Error . Adding more terms gets closer. The series converges rapidly.
Code examples
Beginner example (Python)
import math # Access Euler's number
print(math.e) # 2.718281828459045 # Exponential function: e^x
print(math.exp(1)) # 2.718281828459045 (e^1 = e)
print(math.exp(0)) # 1.0 (e^0 = 1 always)
print(math.exp(2)) # 7.389056098930592 (e^2) # Natural log: ln(x) = log base e of x
print(math.log(math.e)) # 1.0 (ln(e) = 1 by definition)
print(math.log(1)) # 0.0 (ln(1) = 0) # Sigmoid function (common in ML)
def sigmoid(z):
return 1 / (1 + math.exp(-z))
print(sigmoid(0)) # 0.5 (symmetric: z=0 gives 50% probability)
print(sigmoid(2)) # ~0.88
print(sigmoid(-2)) # ~0.12Beginner example (R)
# Euler's number in R
print(exp(1)) # 2.718282 (e^1 = e)
print(exp(0)) # 1 (e^0 = 1)
print(exp(2)) # 7.389056 (e^2) # Natural log
print(log(exp(1))) # 1 (ln(e) = 1)
print(log(1)) # 0 (ln(1) = 0) # Sigmoid
sigmoid <- function(z) 1 / (1 + exp(-z))
cat("sigmoid(0):", sigmoid(0), "\n") # 0.5
cat("sigmoid(2):", sigmoid(2), "\n") # ~0.88Professional example (Python)
import numpy as np
import pandas as pd
# Scenario: binary classification with logistic regression
# Demonstrate how e underlies the sigmoid -> probability -> cross-entropy loss pipeline
np.random.seed(42)
# Simulated raw model scores (logits) for 6 observations
logits = np.array([-3.0, -1.5, -0.5, 0.5, 1.5, 3.0])
labels = np.array([0, 0, 0, 1, 1, 1]) # true binary labels
# Step 1: sigmoid converts logits to probabilities using e
probabilities = 1 / (1 + np.exp(-logits))
# Step 2: cross-entropy loss uses natural log (ln = log base e)
# L_i = -[y_i * ln(p_i) + (1 - y_i) * ln(1 - p_i)]
epsilon = 1e-12 # clip to avoid ln(0)
p_clipped = np.clip(probabilities, epsilon, 1 - epsilon)
cross_entropy_per_obs = -(labels * np.log(p_clipped) + (1 - labels) * np.log(1 - p_clipped))
# Mean cross-entropy loss
log_loss = np.mean(cross_entropy_per_obs)
df = pd.DataFrame({
"logit": logits,
"probability": np.round(probabilities, 4),
"label": labels,
"ce_loss": np.round(cross_entropy_per_obs, 4),
})
print(df.to_string(index=False))
print(f"\nMean Cross-Entropy Loss (log-loss): {log_loss:.4f}")
# e appears in both the sigmoid (e^-z) and the log-loss (ln(p))Professional example (R)
# Scenario: binary classification with logistic regression
# e underlies sigmoid -> probability -> cross-entropy loss pipeline
set.seed(42)
logits <- c(-3, -1.5, -0.5, 0.5, 1.5, 3)
labels <- c(0, 0, 0, 1, 1, 1) # Step 1: sigmoid converts logits to probabilities using e
probabilities <- 1 / (1 + exp(-logits)) # Step 2: cross-entropy loss uses natural log (ln = log base e)
epsilon <- 1e-12
p_clipped <- pmax(pmin(probabilities, 1 - epsilon), epsilon)
cross_entropy_per_obs <- -(labels * log(p_clipped) + (1 - labels) * log(1 - p_clipped))
log_loss <- mean(cross_entropy_per_obs)
df <- data.frame( logit = logits, probability = round(probabilities, 4), label = labels, ce_loss = round(cross_entropy_per_obs, 4)
)
print(df)
cat(sprintf("\nMean Cross-Entropy Loss (log-loss): %.4f\n", log_loss))Source: 1300 p. 217