Loading Plotivy
Preparing your workspace and data.
Loading Plotivy
Preparing your workspace and data.
From linear regression to nonlinear models - a practical guide to fitting scientific research data with scipy, numpy, and publication-ready visualization.
What curve fitting does
Extract parameters and enable prediction from noisy data
Linear vs nonlinear fitting
When to use each approach and why it matters
The scipy.optimize.curve_fit workflow
Defining models, running fits, extracting uncertainties
Linear vs nonlinear comparison
Side-by-side reference for choosing a model
Preprocessing before fitting
Smoothing, peak detection, and outlier handling
Common mistakes
The most frequent errors in scientific curve fitting
Curve fitting finds the mathematical function that best describes the relationship in your experimental data. It converts scattered data points into a quantitative model with defined parameters:
Curve fitting serves two fundamental purposes in scientific research. First, it extracts meaningful parameters: the rate constant of a reaction, the binding affinity of a ligand, the calibration coefficient of an instrument. Second, it enables prediction: given a new input, the fitted model produces an estimate with quantified uncertainty.
Python's scipy.optimize.curve_fit is the standard workhorse. It uses the Levenberg-Marquardt algorithm by default, accepts any user-defined model function, and returns both the optimized parameters and the covariance matrix for confidence interval estimation.
Linear fitting is the simplest case. When the data follow a straight-line relationship - absorbance vs concentration in Beer-Lambert law, signal vs analyte in a calibration curve - ordinary least squares provides an exact, closed-form solution.
Nonlinear fitting becomes necessary when the underlying relationship is curved. Biological systems are full of nonlinear behavior: sigmoidal dose-response curves, hyperbolic enzyme saturation, exponential decay, and Gaussian peak shapes. Unlike linear fitting, nonlinear optimization requires initial parameter guesses and iterative minimization.
| Aspect | Linear | Nonlinear |
|---|---|---|
| Solution method | Exact closed-form (ordinary least squares) | Iterative numerical optimization (Levenberg-Marquardt) |
| Initial guesses required | No | Yes - critical for convergence |
| Convergence failure risk | None | Yes, if guesses are too far from true values |
| Goodness of fit | R-squared is valid | Check residual plots; R-squared can mislead |
| Typical applications | Beer-Lambert, calibration curves, standard curves | Dose-response, enzyme kinetics, Gaussian peaks |
Initial guesses matter: Each technique page addresses the initial guess problem for its specific model. Dose-response curves use the observed minimum and maximum responses. Michaelis-Menten fits estimate Km from the half-maximal rate. Gaussian fits initialize the center from the data peak.
The general workflow is consistent across all nonlinear models:
Important: Reporting fitted parameters without uncertainties is incomplete. A Km of 15 micromolar means something very different with a standard error of 0.5 vs 10. Always extract and report confidence intervals.
Real experimental data often requires cleaning before fitting. Two preprocessing techniques are critical for spectral and signal data.
Reduces high-frequency noise while preserving peak shape - critical when the peak shape itself is what you are fitting. Adjusting window length and polynomial order lets you tune the noise-reduction vs peak-preservation tradeoff.
Identifies individual features in complex data, allowing you to fit each one separately. Detected positions and heights from find_peaks become informed initial guesses for subsequent Gaussian or Lorentzian fits.
Outlier handling is another consideration. A single anomalous data point can pull a fitted curve away from the true trend. Robust fitting methods, iterative outlier rejection, and weighted least squares are strategies covered in the individual technique pages.
Linear (y = mx + b)
Use case: Calibration curves, Beer-Lambert law
Nonlinear (bell curve)
Use case: Spectral peaks, PSF characterization
Nonlinear (sigmoidal / 4PL)
Use case: EC50 and IC50, pharmacology
Nonlinear (hyperbolic)
Use case: Enzyme kinetics
Local polynomial (preprocessing)
Use case: Pre-fit noise reduction
Signal processing (preprocessing)
Use case: Identify peaks before fitting
| Technique | Model Type | Typical Application |
|---|---|---|
| Linear Regression | Linear (y = mx + b) | Calibration curves, Beer-Lambert law |
| Gaussian Fitting | Nonlinear (bell curve) | Spectral peaks, PSF characterization |
| Dose-Response Curve | Nonlinear (sigmoidal / 4PL) | EC50 and IC50, pharmacology |
| Michaelis-Menten Fitting | Nonlinear (hyperbolic) | Enzyme kinetics |
| Savitzky-Golay Smoothing | Local polynomial (preprocessing) | Pre-fit noise reduction |
| Peak Detection | Signal processing (preprocessing) | Identify peaks before fitting |
Upload your dataset and generate publication-ready curve fits with AI-powered analysis. Linear, Gaussian, sigmoidal, and custom models - no installation required.
Start Analyzing