Non-Linear Least-Square Minimization and Curve-Fitting for Python¶
Upgrading scripts from version 0.8.3 to 0.9.0? See Version 0.9.0 Release Notes
Lmfit provides a high-level interface to non-linear optimization and curve
fitting problems for Python. Lmfit builds on and extends many of the
optimization algorithm of
scipy.optimize, especially the
Levenberg-Marquardt method from optimize.leastsq.
Lmfit provides a number of useful enhancements to optimization and data fitting problems, including:
Parameterobjects instead of plain floats as variables. A
Parameterhas a value that can be varied in the fit, have a fixed value, or have upper and/or lower bounds. A Parameter can even have a value that is constrained by an algebraic expression of other Parameter values.
- Ease of changing fitting algorithms. Once a fitting model is set up, one can change the fitting algorithm used to find the optimal solution without changing the objective function.
- Improved estimation of confidence intervals. While optimize.leastsq will automatically calculate uncertainties and correlations from the covariance matrix, the accuracy of these estimates are often questionable. To help address this, lmfit has functions to explicitly explore parameter space to determine confidence levels even for the most difficult cases.
- Improved curve-fitting with the
Modelclass. This extends the capabilities of optimize.curve_fit, allowing you to turn a function that models for your data into a python class that helps you parametrize and fit data with that model.
- Many pre-built models for common lineshapes are included and ready to use.
The lmfit package is Free software, using an MIT license. The software and this document are works in progress. If you are interested in participating in this effort please use the lmfit github repository.
- Getting started with Non-Linear Least-Squares Fitting
- Downloading and Installation
- Getting Help
- Frequently Asked Questions
- What’s the best way to ask for help or submit a bug report?
- Why did my script break when upgrading from lmfit 0.8.3 to 0.9.0?
- I get import errors from IPython
- How can I fit multi-dimensional data?
- How can I fit multiple data sets?
- How can I fit complex data?
- Can I constrain values to have integer values?
- How should I cite LMFIT?
- Performing Fits, Analyzing Outputs
- Modeling Data and Curve Fitting
- Built-in Fitting Models in the
- Peak-like models
- Linear and Polynomial Models
- Step-like models
- Exponential and Power law models
- User-defined Models
- Example 1: Fit Peaked data to Gaussian, Lorentzian, and Voigt profiles
- Example 2: Fit data to a Composite Model with pre-defined models
- Example 3: Fitting Multiple Peaks – and using Prefixes
- Calculation of confidence intervals
- Bounds Implementation
- Using Mathematical Constraints