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
8
votes
3 answers

scipy.optimize.curve_fit, TypeError: unsupported operand type

I've done a search and the problem seems similar to Python scipy: unsupported operand type(s) for ** or pow(): 'list' and 'list' however the solution posted there did not work and I think it may actually be different. I am trying to fit a curve to…
user1889259
  • 245
  • 1
  • 3
  • 7
8
votes
2 answers

Fitting logarithmic curve in R

If I have a set of points in R that are linear I can do the following to plot the points, fit a line to them, then display the line: x=c(61,610,1037,2074,3050,4087,5002,6100,7015) y=c(0.401244, 0.844381, 1.18922, 1.93864, 2.76673, 3.52449, 4.21855,…
user52291
  • 161
  • 2
  • 2
  • 4
8
votes
2 answers

6th degree curve fitting with numpy/scipy

I have a very specific requirement for interpolating nonlinear data using a 6th degree polynomial. I've seen numpy/scipy routines (scipy.interpolate.InterpolatedUnivariateSpline) that allow interpolation only up to degree 5. Even if there's no…
prrao
  • 2,656
  • 5
  • 34
  • 39
7
votes
2 answers

Linear regression in R (normal and logarithmic data)

I want to carry out a linear regression in R for data in a normal and in a double logarithmic plot. For normal data the dataset might be the follwing: lin <- data.frame(x = c(0:6), y = c(0.3, 0.1, 0.9, 3.1, 5, 4.9, 6.2)) plot (lin$x, lin$y) There I…
R_User
  • 10,682
  • 25
  • 79
  • 120
7
votes
1 answer

Sinusoidal fitting classes for c#

I am wondering if there is a class for fitting data to a sine curve. I found an algorithm for it here but it would take some time to first understand and then code... Before I go down that road I am wondering if the forum knows of a class that is…
Richard
  • 15,152
  • 31
  • 85
  • 111
7
votes
3 answers

SciPy global minimum curve fit

I'm using scipy.optimize.curve_fit, but I suspect it is converging to a local minimum and not the global minimum. I tried using simulated annealing in the following way: def fit(params): return np.sum((ydata - specf(xdata,*params))**2) p =…
Gus
  • 4,375
  • 5
  • 31
  • 50
7
votes
2 answers

scipy.curve_fit vs. numpy.polyfit different covariance matrices

I am using Python 3.6 for data fitting. Recently, I came across the following problem and I’m lacking experience wherefore I’m not sure how to deal with this. If I use numpy.polyfit(x, y, 1, cov=True) and scipy.curve_fit(lambda: x, a, b: a*x+b, x,…
user168000
  • 73
  • 1
  • 4
7
votes
2 answers

Interactive BSpline fitting in Python

Using the following function, one can fit a cubic spline on input points P: def plotCurve(P): pts = np.vstack([P, P[0]]) x, y = pts.T i = np.arange(len(pts)) interp_i = np.linspace(0, i.max(), 100000 * i.max()) xi = interp1d(i, x,…
snelzb
  • 157
  • 3
  • 16
7
votes
1 answer

Python power law fit with upper limits & asymmetric errors in data using ODR

I'm trying to fit some data to a power law using python. The problem is that some of my points are upper limits, which I don't know how to include in the fitting routine. In the data, I have put the upper limits as errors in y equal to 1, when the…
7
votes
2 answers

Linear curve fitting with errors

I was looking for a way to perform a linear curve fit in Javascript. I found several libraries, but they don't propagate errors. What I mean is, I have data and associated measurement errors, like: x = [ 1.0 +/- 0.1, 2.0 +/- 0.1, 3.1 +/- 0.2, 4.0…
Luan Nico
  • 5,376
  • 2
  • 30
  • 60
7
votes
2 answers

Fitting partial Gaussian

I'm trying to fit a sum of gaussians using scikit-learn because the scikit-learn GaussianMixture seems much more robust than using curve_fit. Problem: It doesn't do a great job in fitting a truncated part of even a single gaussian peak: from sklearn…
lhcgeneva
  • 1,981
  • 2
  • 21
  • 29
7
votes
2 answers

Iteratively smooth a curve

I've been trying to do this the whole day. Basically, I have a line and a point. I want the line to curve and pass through that point, but I don't want a smooth curve. I wan't to be able to define the number of steps in my curve, like so (beware…
Alex Turpin
  • 46,743
  • 23
  • 113
  • 145
7
votes
2 answers

Fit 3D Polynomial Surface with Python

I have a python code that calculates z values dependent on x and y values. Overall, I have 7 x-values and 7 y-values as well as 49 z-values that are arranged in a grid (x and y correspond each to one axis, z is the height). Now, I would like to fit…
lux7
  • 1,600
  • 2
  • 18
  • 34
7
votes
1 answer

How to fit a line through a 3D pointcloud?

I have a cable I am dropping from moving vehicle onto the ground. Using a camera system I estimate the location where the rope touches the ground in realtime. Movement of the vehicle and inaccuracy in the estimation of the location result in a…
marqram
  • 725
  • 12
  • 26
7
votes
1 answer

How to extract equation from a polynomial fit?

My goal is to fit some data to a polynomial function and obtain the actual equation including the fitted parameter values. I adapted this example to my data and the outcome is as expected. Here is my code: import numpy as np import…
Cleb
  • 25,102
  • 20
  • 116
  • 151