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
16
votes
2 answers

scipy curve_fit raises "OptimizeWarning: Covariance of the parameters could not be estimated"

I am trying to fit this function to some data: But when I use my code import numpy as np from scipy.optimize import curve_fit import matplotlib.pyplot as plt def f(x, start, end): res = np.empty_like(x) res[x < start] =-1 res[x > end]…
Jonas
  • 1,838
  • 4
  • 19
  • 35
16
votes
1 answer

Using scipy.optimize.curve_fit with weights

According to the documentation, the argument sigma can be used to set the weights of the data points in the fit. These "describe" 1-sigma errors when the argument absolute_sigma=True. I have some data with artificial normally-distributed noise which…
xnx
  • 24,509
  • 11
  • 70
  • 109
16
votes
1 answer

Fitting with ggplot2, geom_smooth and nls

I am trying to fit data on an exponential decay function (RC like system) with equation: My data are on the following dataframe: dataset <- data.frame(Exp = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,…
Oneira
  • 1,365
  • 1
  • 14
  • 28
16
votes
3 answers

Use Math.NET's Fit.Polynomial method on functions of multiple parameters

I previously used Math.NET Numerics library's Fit.Polynomial method to fit a cubic polynomial on a set of data that could be modeled as a function of one parameter y=f(x). Now I would like to similarly find a 2 or 3 order polynomial that fits data…
wip
  • 2,313
  • 5
  • 31
  • 47
16
votes
1 answer

Fitting data using UnivariateSpline in scipy python

I have a experimental data to which I am trying to fit a curve using UnivariateSpline function in scipy. The data looks like: x y 13 2.404070 12 1.588134 11 1.760112 10 1.771360 09 1.860087 08 1.955789 07 1.910408 06 …
Prakhar Mehrotra
  • 1,215
  • 4
  • 16
  • 21
16
votes
2 answers

Smooth spline representation of an arbitrary contour, f(length) --> x,y

Suppose I have a set of x,y coordinates that mark points along contour. Is there a way that I can build a spline representation of the contour that I can evaluate at a particular position along its length and recover interpolated x,y coordinates? It…
ali_m
  • 71,714
  • 23
  • 223
  • 298
16
votes
4 answers

Linear / Non-Linear Fit to a Sine Curve

I've had a look at this and this. But I have a slightly different problem. I know that my data is a sine curve, of unknown period and unknown amplitude, with additive non-gaussian distributed noise. I'm attempting to fit it using the GSL non-linear…
Kitchi
  • 1,874
  • 4
  • 28
  • 46
16
votes
5 answers

How does the Levenberg–Marquardt algorithm work in detail but in an understandable way?

Im a programmer that wants to learn how the Levenberg–Marquardt curvefitting algorithm works so that i can implement it myself. Is there a good tutorial anywhere that can explain how it works in detail with the reader beeing a programmer and not a…
Per Arneng
  • 2,100
  • 5
  • 21
  • 32
15
votes
1 answer

Applying bounds to specific variable during curve_fit (scipy) leads to an error

I am trying to apply bounds onto some of the parameters during curve fitting but I'm getting the following error message when I tried to do so: ValueError: too many values to unpack Doesn't each 2-tuple in the bound command corresponds to x0, k,…
Ang Jit Wei Aaron
  • 389
  • 1
  • 3
  • 19
15
votes
3 answers

Catmull-Rom interpolation on SVG Paths

I am experimenting with creating high-performance, good-looking pencil tools using SVG paths. I am logging the mouse coordinates to draw a path. To get a high-fidelity path (accurate to the user's movements) I need to log a point for every pixel…
nicholaswmin
  • 21,686
  • 15
  • 91
  • 167
15
votes
2 answers

Python and lmfit: How to fit multiple datasets with shared parameters?

I would like to use the lmfit module to fit a function to a variable number of data-sets, with some shared and some individual parameters. Here is an example generating Gaussian data, and fitting to each data-set individually: import numpy as…
Merlin
  • 297
  • 1
  • 3
  • 10
15
votes
3 answers

scipy.optimize.curvefit() - array must not contain infs or NaNs

I am trying to fit some data to a curve in Python using scipy.optimize.curve_fit. I am running into the error ValueError: array must not contain infs or NaNs. I don't believe either my x or y data contain infs or NaNs: >>> x_array =…
Bryce Thomas
  • 10,479
  • 26
  • 77
  • 126
14
votes
2 answers

curve fitting with python

I'm trying to fit some data and stuff, I know there is a simple command to do this with python/numpy/matplotlib, but I can't find it. I think it is something like popt,popc = numpy.curvefit(f,x) where popt is the paramters of f, popc is the fit…
Yotam
  • 10,295
  • 30
  • 88
  • 128
14
votes
2 answers

Using Scipy curve_fit with piecewise function

I am getting an optimize warning: OptimizeWarning: Covariance of the parameters could not be estimated category=OptimizeWarning) when trying to fit my piecewise function to my data using scipy.optimize.curve_fit. Meaning no fitting…
lanery
  • 5,222
  • 3
  • 29
  • 43
14
votes
3 answers

Fitting a function in R

I have a few datapoints (x and y) that seem to have a logarithmic relationship. > mydata x y 1 0 123 2 2 116 3 4 113 4 15 100 5 48 87 6 75 84 7 122 77 > qplot(x, y, data=mydata, geom="line") Now I would like to find an…
jnns
  • 5,148
  • 4
  • 47
  • 74