Exponential curve fitting in Python matplotlib
0
0
Entering edit mode
2.3 years ago
Md Abrar • 0

enter image description here

Dear community,

I'm trying to fit an exponential curve without overfitting. Currently, my code uses 3 to 5 parameters for fitting the curve which looks nice but that incurs information cost and overfitting. Could you help me solve this problem where I can generalise these curves using a mathematical function that doesn't overfit?

logx, logy = np.log(x_fake), np.log(y_fake)

p = np.polyfit(logx, logy, 3) #array of polynomial coefficients (including coefficients equal to zero) from highest degree to the constant term
y_fit = np.exp(np.polyval(p, logx)) #polyval->Compute polynomial values.
# output of polyval: [-0.02643303 -0.76953135  5.01703773  3.32237767]

fig,ax=plt.subplots(figsize=[10,7])
ax.loglog(x, y, '.r', linewidth=2)
ax.loglog(x_fake, y_fit, 'b--')
matplotlib python3 • 711 views
ADD COMMENT
1
Entering edit mode

Since your axes are already log-transformed, would you not want to fit a linear trend to this instead?

ADD REPLY

Login before adding your answer.

Traffic: 2512 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6