Search code examples
pythonmachine-learningstatisticscurve-fittingmodeling

Asymptotic regression in Python?


I have this portion of a data-set, where the y values eventually must reach an asymptotic limit. Here is a plot of the first 300 entries:

Asymptotic tendency of data-set

I have seen asymptotic regression (of the form y = b0 + b1*(1-exp(-exp(lrc) * x)) and I think it would be the best model to fit this data. R seemingly already has the function in its libraries, but I cannot find one in Python.

(1) Is there any library function for asymptotic regression or relevant saturation dynamics models as answered by Cleb below? If not, how to model it using scipy.optimize.curve_fit?

(2) Also how to predict the maximum integer value of the curve? Example, If y=2454.1234 is the value at X=10**20 and y=2545.5678 at X=10**50, for a certain model, I want to obtain 2454. Is there any one-shot way, other than linear search?

Thanks for your help.


Solution

  • You can easily fit it using scipy's curve_fit function. I used a different model but you can easily change that.

    The output you get looks as follows:

    enter image description here

    This is the code which is quite self-explanatory:

    import numpy as np
    from scipy.optimize import curve_fit
    import matplotlib.pyplot as plt
    import pandas as pd
    
    
    def f(x, a, b, n):
        return a * x ** n  / (x ** n + b)
    
    
    data = pd.read_csv('data.txt.txt', sep='\t')
    
    y = data['y'].astype(float)
    x = data['X'].astype(float)
    
    popt, pcov = curve_fit(f, x, y, p0=[1800., 20., 1.])
    
    plt.scatter(x, y)
    plt.plot(x, f(x, *popt), 'r-')
    
    plt.show()