liveBook · Manning

Mean

As explained in Machine Learning Algorithms in Depth

A mean is a numerical location parameter representing the average or central value of a probability distribution.

A mean is a numerical location parameter representing the average or central value of a probability distribution. For a Bernoulli random variable with success probability θ, E[X] = θ. section 2.1.1

The mean appears in several computational roles:

  • Estimate an expected value by averaging function evaluations over samples drawn from a distribution. section 2.2
  • Measure expected portfolio return while comparing portfolios by their risk, represented by standard deviation. section 9.2.2
  • Relate a Bernoulli distribution's central value to its variance: E[X] = θ and Var(X) = θ(1 − θ). section 2.1.1

Monte Carlo estimate of π

Draw uniform points in a square, mark whether each lies inside a circle, and average the resulting area contributions. Dividing that empirical mean by the squared radius estimates π; increasing the sample count improves accuracy, with standard error σ/√N. section 2.2

Listing 2.1 Pi estimator
import numpy as np
import matplotlib.pyplot as plt

np.random.seed(42)     #1

def pi_est(radius=1, num_iter=int(1e4)):     #2


    X = np.random.uniform(-radius,+radius,num_iter)
    Y = np.random.uniform(-radius,+radius,num_iter)

    R2 = X**2 + Y**2
    inside = R2 < radius**2
    outside = ~inside

    samples = (2*radius)*(2*radius)*inside

    I_hat = np.mean(samples)
    pi_hat = I_hat/radius ** 2     #3
    pi_hat_se = np.std(samples)/np.sqrt(num_iter)    #4
    print("pi est: {} +/- {:f}".format(pi_hat, pi_hat_se))

    plt.figure()
    plt.scatter(X[inside],Y[inside], c='b', alpha=0.5)
    plt.scatter(X[outside],Y[outside], c='r', alpha=0.5)
    plt.show()

if __name__ == "__main__":

    pi_est()

Shows a NumPy implementation that computes an empirical mean and standard error while estimating π from random samples. section 2.2

How Machine Learning Algorithms in Depth covers it

How deep it goes
Derives the Bernoulli mean, applies empirical averaging, and computes standard error without developing a general estimator theory.
Examples
Uses coin flips, Monte Carlo estimation of π, random portfolios, and exercises involving Bernoulli and Beta distributions.
What it assumes
Assumes probability distributions, random variables, sampling, and variance; develops the Bernoulli mean explicitly.
What you can do after
Apply it via NumPy to calculate empirical means, estimate expected values, and quantify Monte Carlo error.
How it connects
Connects mean to expected value, variance, standard error, Bernoulli distributions, Beta distributions, and mean-variance analysis.

Also explained in

Compare how 29 books explain mean →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning Algorithms in Depth. The section links point to the parts of the book it draws on.