Questions tagged [curve-fitting]

Fitting 1-D curve to data points, minimizing pre-defined error/loss function.

From wiki:

Curve fitting is the process of constructing a curve, or mathematical function, that has the best fit to a series of data points.

3428 questions
41
votes
4 answers

Fitting a closed curve to a set of points

I have a set of points pts which form a loop and it looks like this: This is somewhat similar to 31243002, but instead of putting points in between pairs of points, I would like to fit a smooth curve through the points (coordinates are given at the…
Mahdi
  • 3,188
  • 2
  • 20
  • 33
38
votes
2 answers

Fit sigmoid function ("S" shape curve) to data using Python

I'm trying to fit a sigmoid function to some data I have but I keep getting:ValueError: Unable to determine number of fit parameters. My data looks like this: My code is: from scipy.optimize import curve_fit def sigmoid(x): return…
user88484
  • 1,249
  • 1
  • 13
  • 34
35
votes
5 answers

How can I fit a Bézier curve to a set of data?

I have a set of data points (which I can thin out) that I need to fit with a Bézier curve. I need speed over accuracy, but the fit should be decent enough to be recognizable. I'm also looking for an algorithm I can use that doesn't make much use of…
user791684
  • 386
  • 1
  • 3
  • 6
33
votes
2 answers

Exponential curve fitting in SciPy

I have two NumPy arrays x and y. When I try to fit my data using exponential function and curve_fit (SciPy) with this simple code #!/usr/bin/env python from pylab import * from scipy.optimize import curve_fit x = np.array([399.75, 989.25, 1578.75,…
drastega
  • 1,581
  • 5
  • 30
  • 42
32
votes
2 answers

What's the error of numpy.polyfit?

I want to use numpy.polyfit for physical calculations, therefore I need the magnitude of the error.
varantir
  • 6,624
  • 6
  • 36
  • 57
31
votes
7 answers

Curve fitting unsorted points on a plane

Question: How do you fit a curve to points on a plane if they aren't single valued? For the example shown, how would one fit a curve (like the black one) to the noisy blue data? It's similar to spline smoothing, but I don't know the order of the…
tkw954
  • 940
  • 2
  • 10
  • 16
30
votes
2 answers

Fitting a line in 3D

Are there any algorithms that will return the equation of a straight line from a set of 3D data points? I can find plenty of sources which will give the equation of a line from 2D data sets, but none in 3D. Thanks.
Mike
  • 899
  • 2
  • 12
  • 16
28
votes
4 answers

Fit a gaussian function

I have a histogram (see below) and I am trying to find the mean and standard deviation along with code which fits a curve to my histogram. I think there is something in SciPy or matplotlib that can help, but every example I've tried doesn't work. …
user1496646
26
votes
6 answers

Goodness of fit functions in R

What functions do you use in R to fit a curve to your data and test how well that curve fits? What results are considered good?
medriscoll
  • 26,995
  • 17
  • 40
  • 36
25
votes
3 answers

Why does scipy.optimize.curve_fit not fit to the data?

I've been trying to fit an exponential to some data for a while using scipy.optimize.curve_fit but i'm having real difficulty. I really can't see any reason why this wouldn't work but it just produces a strait line, no idea why! Any help would be…
user1696811
  • 941
  • 4
  • 10
  • 20
24
votes
7 answers

Nonlinear regression with python - what's a simple method to fit this data better?

I have some data that I want to fit so I can make some estimations for the value of a physical parameter given a certain temperature. I used numpy.polyfit for a quadratic model, but the fit isn't quite as nice as I'd like it to be and I don't have…
Jinx
  • 511
  • 1
  • 3
  • 10
24
votes
2 answers

How can I fit a gaussian curve in python?

I'm given an array and when I plot it I get a gaussian shape with some noise. I want to fit the gaussian. This is what I already have but when I plot this I do not get a fitted gaussian, instead I just get a straight line. I've tried this many…
P. Kaur
  • 255
  • 1
  • 2
  • 11
24
votes
1 answer

Curve Fitting to a time series in the format 'datetime'?

Here is my problem: polyfit does not take datetime values, so that I converted datetime with mktime producing the polynomial fit works z4 = polyfit(d, y, 3) p4 = poly1d(z4) For the plot however, I would like the datetime description on the axis…
Corins
  • 241
  • 1
  • 2
  • 3
24
votes
5 answers

How do I put a constraint on SciPy curve fit?

I'm trying to fit the distribution of some experimental values with a custom probability density function. Obviously, the integral of the resulting function should always be equal to 1, but the results of simple scipy.optimize.curve_fit(function,…
Axon
  • 547
  • 2
  • 6
  • 14
23
votes
1 answer

Why isn't `curve_fit` able to estimate the covariance of the parameter if the parameter fits exactly?

I don't understand curve_fit isn't able to estimate the covariance of the parameter, thus raising the OptimizeWarning below. The following MCVE explains my problem: MCVE python snippet from scipy.optimize import curve_fit func = lambda x, a: a *…
finefoot
  • 9,914
  • 7
  • 59
  • 102