I'm trying to fit a few X-Y points that look like exponential.
I used the following scipy code:
import numpy as np
import scipy
import scipy.optimize
def custom_exponential(x, k, h):
return np.exp(k * x) / h
x_data = np.array([10, 20, 30, 40, 50, 60, 70, 80, 90, 99])
y_data = np.array([6, 25, 88, 243, 560, 1177, 2296, 4191, 7210, 11163])
params, covariance = scipy.optimize.curve_fit(custom_exponential, x_data, y_data)
k_fit, h_fit = params
print("Fitted parameters:")
print("k =", k_fit)
print("h =", h_fit)
but got the result:
Fitted parameters: k = 0.7294449661802176 h = -1.601884017897473e+35
which is nonsense (negative, 10^35...).
By fiddling numbers on an excel sheet I got to the very rough solution y = exp(0.05*x)/0.012 which doesn't look terrible on plot:
How to get a better solution (with scipy or something else)?