SciPy - Curve Fitting and Regression
Identify the error in the following code snippet that attempts to fit a custom exponential model:
import numpy as np
from scipy.optimize import curve_fit
def exp_model(x, a, b):
return a * np.exp(b * x)
xdata = np.array([0, 1, 2, 3])
ydata = np.array([1, 2.7, 7.4, 20.1])
popt, pcov = curve_fit(exp_model, xdata, ydata)
print(popt)