ANALYSIS TOOL BOX

Calculus

FindMinimumSquareLoss

Find the parameter value that minimizes squared loss between observed data and a model function.

calculusderivativesintegralsoptimization

Introduction

When you have a model and real observations, the natural question is "how wrong is this model, and what parameter value makes it least wrong?" FindMinimumSquareLoss answers this by symbolically minimizing squared error — differentiating the loss function and solving for the parameter that drives it to its minimum, rather than searching numerically. Reach for it when you need an exact, defensible answer to a least-squares fitting question: which parameter best reconciles a model's predictions with observed evidence, penalizing large misses more heavily than small ones.

Teaching Note

Squared loss grows rapidly as errors increase. This makes least-squares methods especially sensitive to large deviations, which is often desirable when large errors correspond to analytically meaningful failures rather than random noise.

Parameters

ParameterTypeDefaultDescription
observed_valuesrequiredObserved dependent variable values (e.g., incidents, biomarker levels, risk scores).
predicted_valuesrequiredPredicted dependent variable values (e.g., incidents, biomarker levels, risk scores).
show_plotboolFalseIf True, plots observed data against the fitted model.
**plot_kwargsAdditional keyword arguments passed to the plotting routine.

Returns

The parameter value that minimizes the squared loss between observed data and the model.

Example

python
from analysistoolbox.calculus import FindMinimumSquareLoss

# Find the parameter value that best fits predicted values to observed values
FindMinimumSquareLoss(
    observed_values=[1, 2, 3, 4],
    predicted_values=[2.1, 4.2, 5.9, 8.3],
    show_plot=True
)