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
1 answer

Restricting values for curve_fit (scipy.optimize)

I'm trying to fit a logistic growth curve to my data using curve_fit using the following function as the input. def logistic(x, y0, k, d, a, b): if b > 0 and a > 0: y = (k * pow(1 + np.exp(d - (a * b * x) ), (-1/b) )) + y0 elif b >=…
mgalardini
  • 1,397
  • 2
  • 16
  • 30
8
votes
1 answer

Fitting two curves with linear/non-linear regression

I need to fit two curves(which both should belong to cubic functions) into a set of points with JuMP. I've done fitting one curve, but I'm struggling at fitting 2 curves into same dataset. I thought that if I can distribute points to curves - so if…
8
votes
3 answers

Fitting a Logistic Curve to Data

I would like to fit a logaritmic function to some data with scipy. Unfortunatley I get the following error: Covariance of the parameters could not be estimated How can I prevent this? import numpy as np import scipy.optimize as opt import…
8
votes
1 answer

Fitting a quadratic function in python without numpy polyfit

I am trying to fit a quadratic function to some data, and I'm trying to do this without using numpy's polyfit function. Mathematically I tried to follow this website https://neutrium.net/mathematics/least-squares-fitting-of-a-polynomial/ but somehow…
Ahmad Moussa
  • 876
  • 10
  • 31
8
votes
1 answer

Piecewise linear fit with n breakpoints

I have used some code found in the question How to apply piecewise linear fit in Python?, to perform segmented linear approximation with a single breakpoint. The code is as follows: from scipy import optimize import matplotlib.pyplot as plt import…
Erlend Vollset
  • 103
  • 1
  • 9
8
votes
2 answers

Best Fit Line on Log Log Scales in python 2.7

This is a network IP frequency rank plot in log scales. After completing this portion, I am trying to plot the best fit line on log-log scales using Python 2.7. I have to use matplotlib's "symlog" axis scale otherwise some of the values are not…
coderWorld
  • 602
  • 1
  • 8
  • 28
8
votes
2 answers

In Java, does an implementation exist for interpolating non-uniformly distributed time series data?

I have some matlab code which requires time series data that is uniformly distributed in time to produce an answer. The driver matlab code which reads the data file also runs an interp1( x, y, xi, 'cubic') on the data after it reads the file…
Jay R.
  • 31,911
  • 17
  • 52
  • 61
8
votes
2 answers

Scatter plot kernel smoothing: ksmooth() does not smooth my data at all

Original question I want to smooth my explanatory variable, something like Speed data of a vehicle, and then use this smoothed values. I searched a lot, and find nothing that directly is my answer. I know how to calculate the kernel density…
hajar
  • 103
  • 1
  • 1
  • 5
8
votes
1 answer

centerline of a polygonal blob (binary image)

I have a binary image of a worm (blob extraction which works well). I am interested in fitting a centerline on the blob (worm). So far I came up with this: starting from a polygon (after outline extraction of blob in the image) I applied a voronoi…
Gabriel
  • 8,990
  • 6
  • 57
  • 101
8
votes
1 answer

SciPy Curve Fit Fails Power Law

So, I'm trying to fit a set of data with a power law of the following kind: def f(x,N,a): # Power law fit if a >0: return N*x**(-a) else: return 10.**300 par,cov =…
Ben
  • 459
  • 4
  • 16
8
votes
2 answers

Create scipy curve fitting definitions for fourier series dynamically

I'd like to achieve a fourier series development for a x-y-dataset using numpy and scipy. At first I want to fit my data with the first 8 cosines and plot additionally only the first harmonic. So I wrote the following two function defintions: #…
Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
8
votes
1 answer

OpenCV: fit the detected edges

I detected the edges of a water wave by using canny edge detection. However, I want to fit a curve for this edge. Is that possible in OpenCV? Here is the image before edge detection: Here is the result of the edge detection operation: The code…
VaFancy
  • 145
  • 2
  • 4
  • 13
8
votes
5 answers

Turning a bunch of numeric attributes into a single score

This comes up a lot and it's surprising there doesn't seem to be a standard solution. Say I have a bunch of numeric attributes -- you can imagine using this for ranking colleges or cities based on a bunch of component scores like student/teacher…
dreeves
  • 26,430
  • 45
  • 154
  • 229
8
votes
2 answers

Why does scipy.optimize.curve_fit not produce a line of best fit for my points?

I have a set of data points, (x and y in the code below) and I am trying to create a linear line of best fit through my points. I am using scipy.optimize.curve_fit. My code produces a line, but not a line of best fit. I have tried giving the…
Lizi Swann
  • 93
  • 2
  • 7
8
votes
1 answer

Python - R square and absolute sum of squares obtainable by scipy.optimize curve_fit?

I am fitting curves using curve_fit. Is there a way to read out the coefficient of determination and the absolute sum of squares? Thanks, Woodpicker
Woodpicker
  • 201
  • 3
  • 8