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.
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
| Parameter | Type | Default | Description |
|---|---|---|---|
observed_valuesrequired | | — | Observed dependent variable values (e.g., incidents, biomarker levels, risk scores). |
predicted_valuesrequired | | — | Predicted dependent variable values (e.g., incidents, biomarker levels, risk scores). |
show_plot | bool | False | If True, plots observed data against the fitted model. |
**plot_kwargs | | — | Additional keyword arguments passed to the plotting routine. |
Returns
The parameter value that minimizes the squared loss between observed data and the model.
Example
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
)