python求e^x_使用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 with the x and y vectors. Note that the residuals

# function also calls the _eNegX_ function. This will return the parameters p that

# minimize

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值