Build inputs from evidenceLesson 21 of 76 · 8 min

Fit a shape and inspect the fit

Fit a positive distribution and compare its quantiles with the input evidence.

A fitted distribution estimates parameters from observations. It can interpolate between observed values and extrapolate beyond them, but its shape is another assumption. Parameter fitting does not establish that the distribution is suitable.

Fit a lognormal model to invented positive waits with loc=0. SciPy's shape is the SD of log(wait), and scale is exp(the mean of log(wait)); loc shifts the whole distribution. For NumPy's earlier generator this means SciPy shape=log_sd and scale=exp(log_mean). For example, log_mean=log(10) and log_sd=.7 correspond to shape=.7, loc=0, scale=10.

Compare empirical and fitted quantiles before using the fitted tail in a decision. A reasonably matching centre does not guarantee a matching tail. With a small sample, both fit assessment and parameter estimates are uncertain, so retain the observations and show sensitivity to plausible alternatives.

θ^\widehat\theta means fitted parameters; the hat marks an estimate from the finite observations.

Fit, then challenge predictions
  1. Input evidence

    observed durations

  2. Fit a positive distribution
    θ^\widehat\theta
  3. Compare quantiles

    empirical versus fitted

Reference illustration. The fit estimates a lognormal shape with location fixed at zero. A converged fit does not establish the tail or the support; fitted predictions beyond the observed sample need validation.

Does a successful fit call establish that the fitted tail is realistic?

Write a prediction (optional)

Seeded teaching simulation

Select Run Python below with the code unchanged.

Tools
About Python ↗

The code is editable. Press Ctrl+Enter or ⌘+Enter to run Python from the editor.

Published example output

This result comes from the original Python. Your runs appear above. Build environment ↗

Empirical quantiles: [1.56 2.65 5.49]
Fitted quantiles: [1.4   2.742 5.371]
Fitted shape, loc, scale: 0.5246 0 2.742

Read the first result

The fitted model makes predictions between and beyond observations. Those predictions need validation, not merely a converged optimiser.

Try an edit

Record the first quantiles. Delete , 7.2 from the end of observed for a separate comparison. Select Run Python again. Compare the last values in Empirical quantiles and Fitted quantiles with the first run. What did the model’s fitted P90 do when the largest observation was omitted?

Back to the Python editor

Scope. Ten invented values are not sufficient to establish a reliable real-world tail. The fit also treats observations as independent.

Try a fresh case

Two candidate models fit the middle of a small sample similarly but predict different extremes. What is useful?

Choose an answer
Need a hint?
Hint 1

Identify which part of the distribution the decision uses.

Hint 2

Compare the candidate predictions in that region.

Your notes