小编Med*_*ath的帖子

使用scipy,python,numpy的非线性e ^( - x)回归

下面的代码给出了一条最佳拟合线的平直线,而不是沿着适合数据的e ^( - x)模型的漂亮曲线.任何人都可以告诉我如何修复下面的代码,以便它适合我的数据?

import numpy as np  
import matplotlib.pyplot as plt
import scipy.optimize

def _eNegX_(p,x):
    x0,y0,c,k=p  
    y = (c * np.exp(-k*(x-x0))) + y0
    return y

def _eNegX_residuals(p,x,y):
    return y - _eNegX_(p,x)

def Get_eNegX_Coefficients(x,y):
    print 'x is:  ',x  
    print 'y is:  ',y 

    # Calculate p_guess for the vectors x,y.  Note that p_guess is the
    # starting estimate for the minimization.
    p_guess=(np.median(x),np.min(y),np.max(y),.01)

    # Calls the leastsq() function, which calls the residuals function with an initial 
    # guess for the parameters and …
Run Code Online (Sandbox Code Playgroud)

python statistics numpy scientific-computing scipy

7
推荐指数
1
解决办法
4413
查看次数

标签 统计

numpy ×1

python ×1

scientific-computing ×1

scipy ×1

statistics ×1