0
votes

I'm trying to fit curve with scipy.optimize.curve_fit.

my data:

x = [3,4,5,6,8,10,12]
y = [30,25,23,22,21,18,14]

func like this

def func(x, b, c, d, a):
        return b * (x+a)**c + d

curve_fit parameters

bounds=[-50,50],  p0 = [50,-1,10,1],  maxfev = 50000)

link to curve

But as you see, the curve is not very accurate. I assume that I need to use another type of function. Or maybe there another tool for this task? All I need to get formula y = F(x) and predict y-values not only on [3,12], under 3 and above 12 too.

p.s. I have several such x-y lists and maybe there are different functions type in different data

1
The first step should be finding out what these numbers mean, how a "natural" function would look like (and why) and what the expected error between function and measured values are. This is not a mathematical nor a programming problem, good knowledge of the source of the data is essential here.JohanC
You might want to check out numpy.polyfit, but I agree with @JohanC, the nature of the source data here is really what's important. More info on the data is necessary for us to provide any reasonable aid. I'd also recommend to scale the axes and plot non-dimensinal data, if you haven't already done so.. with legends. This other post may (or may not) be of help to you: stackoverflow.com/questions/59676871Wololo
@Anthony Wicker for extending you fitting plot create function that will generate new data sets based on fitting results, then plot it.Zaraki Kenpachi
As mentioned my @JohanC the origin of the data defines your model, i.e. your fit function. Therefore, "not very accurate" is problematic. To what extend do you have to extrapolate? Data suggests that integer input maps on integer output. Is this an issue? Can you explain the origin of the data, can you show other data sets?mikuszefski

1 Answers

0
votes

You wrote "the curve is not very accurate". What do you mean ? Accurate with what criteria of proximity ? Accurate with respect to what model (definitively specified or still to be chosen) ?

In the function that you choose y(x)= b*(x+a)^c +d they are 4 adjustable parameters. With the same number of parameters, see for example the linear least squares fitting of the function y(x)= a + b * x + c * x^2 +d * x^3 below :

enter image description here