Entering edit mode
2.3 years ago
Md Abrar
•
0
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--')
Since your axes are already log-transformed, would you not want to fit a linear trend to this instead?