I have a question about a simple fit function in Python. I am trying to fit two different functions on a data set and the border between the two regimes should be also a fit parameter. Very naively I was trying something like this:
def FitFunc(x, a, b, c, d, e, border):
if x < border:
return a * x + b
if x > border:
return c * x**2 + d * x + e
But I got a ValueError:
The truth value of a Series is ambiguous. Use a.empty(), a.bool(), a.item(), a.any() or a.all()
I understand that you can not compare my x array to an integer value (which is not even assigned to a fixed value, this should be done by the curve_fit procedure).
I was not able to find a solution for this supposedly simple problem. Can someone help me out of this?
Thanks in advance!
EDIT: I constructed an example:
For the data with x<5 this is perfectly described by a linear function (y=x-3), For x>5 this is perfectly described by a square function (y=x**2/5-3*x/5). Assume you don't know that x is the perfect 'border', is there a way to let curve_fit find out?