lmfit/lmfit-py

Non-Linear Least Squares Minimization, with flexible Parameter settings, based on scipy.optimize, and with many additional classes and methods for curve fitting.

What it solves

LMfit simplifies non-linear least-squares minimization and curve fitting. It addresses the complexity of managing fitting parameters by allowing users to define them as named objects with specific attributes, rather than just raw values. This makes optimization routines more flexible, easier to read, and simpler to modify at runtime.

How it works

Built on top of Scipy and Numpy, the library allows you to define a Parameters object where each variable can be fixed, set within specific bounds, or constrained by mathematical expressions involving other parameters. You write an objective function that uses these parameters to calculate residuals, and the library handles the minimization process. It also provides a Model class that automatically extracts parameters from your model functions, making it easier to combine and reuse models for curve fitting.

Who it’s for

This tool is designed for researchers, data scientists, and developers who need to perform robust curve fitting or parameter optimization in Python and want a more structured, intuitive interface than standard optimization libraries provide.

Highlights

  • Named parameters with support for bounds, constraints, and fixed values.
  • Automatic estimation of parameter uncertainties and correlations.
  • Support for various optimization algorithms, including Levenberg-Marquardt and others from Scipy.
  • Built-in Model class to simplify common curve-fitting tasks.
  • Ability to explore and evaluate confidence intervals for fit results.

Related

  • Project
  • Project
  • Project
  • Project