scipy.optimize.curve_fit的用法

举例

​
from scipy import optimize

import matplotlib.pyplot as plt

import numpy as np

x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ,11, 12, 13, 14, 15])

y = np.array([5, 7, 9, 11, 13, 15, 28.92, 42.81, 56.7, 70.59, 84.47, 98.36, 112.25, 126.14, 140.03])

# 定义一个函数,x为函数的输入,x0,a,c为需要估计的参数
def func(x,x0,a,c):
    return a*(x-x0)**c


p,v = optimize.curve_fit(piecewise_linear, x, y)
# p 为估计出来的参数,v为参数的协方差

xd = np.linspace(0,16,100)
plt.plot(x,y,"o")
plt.plot(xd, func(xd,*p))
plt.show()

​

你可能感兴趣的:(scipy,python,numpy)