Python 数据集的指数曲线拟合

Python 数据集的指数曲线拟合,python,numpy,matplotlib,curve-fitting,exponential,Python,Numpy,Matplotlib,Curve Fitting,Exponential,为了创建指数曲线拟合曲线图,我的下一步是什么?下面是一个将数据拟合到对数二次方程的示例,该对数二次方程比指数拟合更好,并根据原始数据的散点图绘制拟合曲线。这段代码不是最优的,例如,它会重复执行X的日志,而不是只执行一次。直接使用线性拟合方法也可以更有效地拟合log(x)数据,但是在这里,您可以更轻松地用指数代替拟合方程,代码更改更少 import numpy as np import matplotlib.pyplot as plt points = np.array([ (333, 195

为了创建指数曲线拟合曲线图,我的下一步是什么?

下面是一个将数据拟合到对数二次方程的示例,该对数二次方程比指数拟合更好,并根据原始数据的散点图绘制拟合曲线。这段代码不是最优的,例如,它会重复执行X的日志,而不是只执行一次。直接使用线性拟合方法也可以更有效地拟合log(x)数据,但是在这里,您可以更轻松地用指数代替拟合方程,代码更改更少

import numpy as np
import matplotlib.pyplot as plt

points = np.array([
 (333, 195.3267),
 (500, 223.0235),
 (1000, 264.5914),
 (2000, 294.8728),
 (5000, 328.3523),
 (10000, 345.4688)
])

# get x and y vectors
x = points[:,0]
y = points[:,1]
可能重复的
import numpy
import matplotlib
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

points = numpy.array([(333, 195.3267), (500, 223.0235), (1000, 264.5914), (2000, 294.8728
), (5000, 328.3523), (10000, 345.4688)])
# get x and y vectors
xData = points[:,0]
yData = points[:,1]

# function to be fitted
def LogQuadratic(x, a, b, c):
    return a + b*numpy.log(x) + c*numpy.power(numpy.log(x), 2.0)


# some initial parameter values
initialParameters = numpy.array([1.0, 1.0, 1.0])

fittedParameters, pcov = curve_fit(LogQuadratic, xData, yData, initialParameters)

# values for display of fitted function
a, b, c = fittedParameters

# for plotting the fitting results
xPlotData = numpy.linspace(min(xData), max(xData), 50)
y_plot = LogQuadratic(xPlotData, a, b, c)

plt.plot(xData, yData, 'D') # plot the raw data as a scatterplot
plt.plot(xPlotData, y_plot) # plot the equation using the fitted parameters
plt.show()

print('fitted parameters:', fittedParameters)