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
11
votes
4 answers

How to fit more than one line to data points

I am trying to fit more than one line to a list of points in 2D. My points are quite low in number (16 or 32). These points are coming from a simulated environment of a robot with laser range finders attached to its side. If the points lie on a…
hyperknot
  • 13,454
  • 24
  • 98
  • 153
11
votes
2 answers

When to choose nls() over loess()?

If I have some (x,y) data, I can easily draw straight-line through it, e.g. f=glm(y~x) plot(x,y) lines(x,f$fitted.values) But for curvy data I want a curvy line. It seems loess() can be used: f=loess(y~x) plot(x,y) lines(x,f$fitted) This question…
Darren Cook
  • 27,837
  • 13
  • 117
  • 217
11
votes
3 answers

How to fit polynomial to data with error bars

I am currently using numpy.polyfit(x,y,deg) to fit a polynomial to experimental data. I would however like to fit a polynomial that uses weighting based on the errors of the points. I have found scipy.curve_fit which makes use of weights and I…
Jdog
  • 10,071
  • 4
  • 25
  • 42
11
votes
2 answers

Numba jit with scipy

So I wanted to speed up a program I wrote with the help of numba jit. However jit seems to be not compatible with many scipy functions because they use try ... except ... structures that jit cannot handle (Am I right with this point?) A relatively…
Katermickie
  • 213
  • 1
  • 2
  • 5
11
votes
2 answers

Is there a way to get the error in fitting parameters from scipy.stats.norm.fit?

I have some data which I have fitted a normal distribution to using the scipy.stats.normal objects fit function like so: import numpy as np …
SomeRandomPhysicist
  • 1,531
  • 4
  • 19
  • 42
11
votes
3 answers

Using scikit-learn LinearRegression to plot a linear fit

I am trying to make linear regression model that predicts the son's length from his father's length import numpy as np import pandas as pd from matplotlib import pyplot as plt import seaborn as sns %matplotlib inline from sklearn.linear_model import…
user5573514
11
votes
2 answers

Add constraints to scipy.optimize.curve_fit?

I have the option to add bounds to sio.curve_fit. Is there a way to expand upon this bounds feature that involves a function of the parameters? In other words, say I have an arbitrary function with two or more unknown constants. And then let's also…
Peter
  • 377
  • 1
  • 4
  • 15
11
votes
4 answers

How to apply Box-Cox transformation in Python?

I have data of the form: X Y 3.53 0 4.93 50 5.53 60 6.21 70 7.37 80 9.98 90 16.56 100 And I want to find out n so that this can be fit to a function of the form: I am trying to determine n by Box-Cox transformation. How can…
Tom Kurushingal
  • 6,086
  • 20
  • 54
  • 86
11
votes
2 answers

Linear fitting in python with uncertainty in both x and y coordinates

Hi I would like to ask my fellow python users how they perform their linear fitting. I have been searching for the last two weeks on methods/libraries to perform this task and I would like to share my experience: If you want to perform a linear…
Delosari
  • 677
  • 2
  • 17
  • 29
11
votes
1 answer

Quantifying the quality of curve fit using Python SciPy

I'm using Scipy curve_fit to fit a Gaussian curve to data, and am interested in analysing the quality of the fit. I know curve_fit returns a useful pcov matrix, from which the standard deviation of each fitting parameter can be computed as…
IanRoberts
  • 2,846
  • 5
  • 26
  • 33
11
votes
6 answers

Finding a curve to match data

I'm looking for a non-linear curve fitting routine (probably most likely to be found in R or Python, but I'm open to other languages) which would take x,y data and fit a curve to it. I should be able to specify as a string the type of expression I…
Nosredna
  • 83,000
  • 15
  • 95
  • 122
11
votes
2 answers

Weighted trendline

Excel produces scatter diagrams for sets of pair values. It also gives the option of producing a best fit trendline and formula for the trendline. It also produces bubble diagrams which take into consideration a weight provided with each value.…
Tams
  • 182
  • 1
  • 1
  • 8
11
votes
2 answers

Vertical line fit using polyfit

Its just a basic question. I am fitting lines to scatter points using polyfit. I have some cases where my scatter points have same X values and polyfit cant fit a line to it. There has to be something that can handle this situation. After all, its…
Naresh
  • 633
  • 1
  • 7
  • 26
11
votes
2 answers

Playing perfect Tetris: how to align and scale two curves using scaling and translation?

Given parameters of scaling on the y axis (s) and translation on the x axis (t), how to scale and align two curves that do not coincide when the purpose is to maximize curve superposition (not minimize distance)? As indicated by @DWin, this could be…
Etienne Low-Décarie
  • 13,063
  • 17
  • 65
  • 87
11
votes
3 answers

trying to get reasonable values from scipy powerlaw fit

I'm trying to fit some data from a simulation code I've been running in order to figure out a power law dependence. When I plot a linear fit, the data does not fit very well. Here's the python script I'm using to fit the data: #!/usr/bin/env…
zje
  • 3,824
  • 4
  • 25
  • 31