我只是试图将一条曲线拟合到一堆看起来像逻辑函数的点上,结果就像是一条纠结的曲线。
这是代码:
from scipy.optimize import curve_fit
def logistic(v, m, n, a, t):
return a * (1 + m * np.exp(-v/t))/(1 + n * np.exp(-v/t))
def power_curve_fit(xvalues, yvalues):
xdata = xvalues
ydata = yvalues
popt, pcov = curve_fit(logistic, xdata, ydata)
pc = pd.DataFrame()
pc['wind_speed'] = xdata
pc['power_gen'] = ydata
pc['Fit'] = logistic(xdata, *popt)
plt.plot(xdata, logistic(xdata, *popt), 'red')
plt.scatter(xdata, ydata, c='pink', marker='o')
return pc
谢谢!