I'm trying to fit a dataset to a curve for while, but I'm not managing.
The goal is to obtain a curve with equation that fits the data so I can get the parameter x to any value of y.
The blue dataset is the measurement of the soil parameter at the field, and the orange dataset is the measurement of the parameter at the lab.

I already have limited the min and max value for values that make sense in real life, and I have applied the outlier cleaner for the quartile of 0.25/0.75
def remove_outlier(df_in, col_name):
q1 = df_in[col_name].quantile(0.25)
q3 = df_in[col_name].quantile(0.75)
iqr = q3-q1 #Interquartile range
fence_low = q1-1.5*iqr
fence_high = q3+1.5*iqr
df_out = df_in.loc[(df_in[col_name] > fence_low) & (df_in[col_name] < fence_high)]
return df_out
and when I try to fit the data with scipy:
def fit_ocr(x,a,b):
return a/x + b
param, param_cov = curve_fit(fit_ocr, x, y)
a = param[0]
b = param[1]
test_fit = fit_ocr(x,a,b)
That's what I get:
