Non-linear curve fitting in SciPy: Basics

Least-squares and how to do it Python

Julio Cárdenas-Rodríguez
1 min readFeb 28, 2017

Non-linear curve fitting (or non-linear parametric regression)is a fundamental part of the quantitative analysis performed in multiple scientific disciplines. The main idea is that we know (or assume) the model that describes an observed data. For example, lets say we collected data that looks like this:

Some data, is described by an exponential decay?

It would seem reasonable to assume that this curve is described by an exponential decay function of the form `S= a * exp(-xdata/b)`. Then, how we test that this assumption is correct and estimate a and b ?.
We find the values for a and b that minimize the square of the residuals between the predicted data assuming the exponential model and the observed data. In the next section I present a python code to perform non-linear curve fitting on a simulated curve.

Python Code for non-linear curve fitting

--

--

Julio Cárdenas-Rodríguez
Julio Cárdenas-Rodríguez

Written by Julio Cárdenas-Rodríguez

Scientist, modeling geek, immigrant, father, writer-at-heart, scientifically religious, and many other contradictions.

No responses yet