Curve Fitter
Type the equation you want to fit, in your own variable names. The fit runs as you type and gives each parameter with its uncertainty, a plot you can style for a paper, and the Python script that reproduces both.
Plot
Your data and the fitted curve will appear here
Add data on the left and type the equation above, or load an example.
Results
Add data and an equation. The fit runs as you type.
| Parameter | Value ± std. error | 95% interval |
|---|
Parameter correlations
Values near ±1 mean the data fix only a combination of the two parameters; they are marked when |r| > 0.95.
How these numbers are computed
Python script fit.py
Runs with Python 3, numpy, scipy and matplotlib 3.6 or later (3.11 or later to match the preview): python fit.py. It prints the parameters and saves the figure.
How to fit an equation to your data
Paste the data, type the equation, and read the parameters; the plot and the Python script follow every change. Nothing leaves your browser.
Add your data
Paste columns of numbers, drop a file anywhere on the fitter or open one (.csv, .tsv, .txt, .dat). Tabs, commas, semicolons and spaces all work; with semicolons, tabs or spaces a decimal comma such as 1,5 is read as 1.5. A first row of names, such as Time (s), names the columns (time).
Type the equation
Write it in your own names, such as y = A*exp(-t/tau) + y0, or start from a preset. The page shows how it read the equation and points at any mistake. Check that each variable reads the right column, and add starting values, bounds or fixed values if you need them.
Read the results
Each parameter comes with its standard error, 95% confidence interval and relative uncertainty, and the fit with R², RMSE, AIC and BIC (reduced χ² when you give uncertainties). Warnings say in words when a parameter is poorly determined. Copy the table as text, CSV or LaTeX.
Style and export the plot
Set the figure size, fonts, axis labels, ticks, colours, a residual panel and the confidence band. The preview is the exported figure in miniature. Export it as PDF, PNG or SVG.
Take the Python script
Copy or download the script. It holds the data, or reads it from a CSV file you download beside it, fits it with curve_fit, prints the same parameters and saves the same figure.
Come back later
The page remembers your equation, column choices, parameter settings and plot style in this browser, and the data too when it is under 200 kB. Reset clears it all.
How the fitting works
Your equation, read as mathematics
The equation is parsed into a tree, never run as code, so it can only compute arithmetic. 2x and 3(x + 1) multiply, ^ and ** are powers, and bx is one name (write b*x). A likely slip, such as t/2tau or a misspelt function, is pointed out with the reading the page used.
Non-linear least squares
The parameters minimise the sum of squared residuals on your data as given, with no log transform. The minimiser is Levenberg–Marquardt with exact derivatives of your equation, as SciPy’s curve_fit uses when there are no bounds. With uncertainties, each residual is divided by its σ.
Starting values found for you
Parameters the equation is linear in are solved exactly for each trial value of the others, and the rest are searched over several decades. A frequency or period inside sin or cos starts from the strongest periodicity in the data (a Lomb–Scargle periodogram), and frequencies too high for the spacing of the points to show are never tried. When a fit ends poorly the page tries again from other starting points. Any starting value, bound or fixed value you give is respected.
Uncertainties as SciPy reports them
Standard errors come from the covariance matrix, scaled by the reduced χ² unless your uncertainties are absolute, exactly as curve_fit does with absolute_sigma. The 95% intervals use Student’s t. Parameters the data cannot separate are named, with a suggestion.
The mathematics behind the fit
The fit minimises the weighted sum of squared residuals, and every number the page reports follows scipy.optimize.curve_fit.
For a model f(x;\,\theta) with parameters \theta, the fit minimises
Levenberg–Marquardt takes steps \delta that solve, with the Jacobian J_{ij}=\partial f(x_i)/\partial\theta_j and the residuals r,
The covariance of the p free parameters, the standard errors and the 95% intervals are
where s^2=1 when the uncertainties are absolute. The confidence band around the curve carries C through the gradient of f with respect to the parameters (the delta method).
Goodness of fit, with \bar y_w the weighted mean of y:
RMSE is unweighted and in the units of y. R^2, AIC and BIC use the weights when you give uncertainties. AIC and BIC compare models fitted to the same data: lower is better. A fixed parameter does not count in p.
References & documentation
- Levenberg, K. (1944). A method for the solution of certain non-linear problems in least squares. Quarterly of Applied Mathematics, 2(2), 164–168.
- Marquardt, D. W. (1963). An algorithm for least-squares estimation of nonlinear parameters. Journal of the Society for Industrial and Applied Mathematics, 11(2), 431–441.
- Moré, J. J. (1978). The Levenberg–Marquardt algorithm: implementation and theory. In Numerical Analysis, Lecture Notes in Mathematics 630, 105–116. Springer.
- Nielsen, H. B. (1999). Damping parameter in Marquardt’s method. Report IMM-REP-1999-05, Technical University of Denmark.
- Virtanen, P., Gommers, R., Oliphant, T. E., et al. (2020). SciPy 1.0: fundamental algorithms for scientific computing in Python. Nature Methods, 17, 261–272. curve_fit documentation.
- Heckert, N. A., Filliben, J. J., Croarkin, C., et al. (2002). NIST/SEMATECH e-Handbook of Statistical Methods, Ch. 4 “Process Modeling”. itl.nist.gov/div898/handbook.
Frequently asked questions
Is my data sent to a server?
Do the results match SciPy?
scipy.optimize.curve_fit with the Levenberg–Marquardt method, and the covariance, standard errors and confidence intervals are computed as curve_fit computes them, including the absolute_sigma setting. The script the page writes starts from the page’s result and prints the same values. With bounds, SciPy switches to its trust-region method, which ends in the same place when the fit settles inside the bounds.How does the page decide which names are fitted?
pi or e is a parameter. The variable is the one listed in f(x) =, or a usual name such as x, t, T or V, or a name that matches a column header. You can move any name between variable and parameter, and fit e as a parameter if you meant one.What if the fit finds a poor curve or does not converge?
Why does it say two parameters cannot be told apart?
k = A*exp(-Ea/(R*T)) only the ratio Ea/R matters, so R has to be held at its known value. The page recognises common physical constants (R, k_B, N_A, F, h, hbar, Vt) and offers to hold them fixed.What do the standard errors and confidence intervals mean?
What are the uncertainty column and “absolute”?
Can I fit a function of two variables?
z = a*x + b*y + c, or list the variables as f(x, y) =, and give each its column. The plot then shows the observed values against the fitted ones, with the line where they would be equal.Runs entirely in your browser, no data leaves your device.