Python statsmodels曲线拟合(拟合更多高级公式)

问题描述 投票:0回答:1

我在状态模型中实现公式时遇到一些问题。 (我第一次使用它们)我发现具有很强的统计背景:R2 / adj-R2 / AIC / BIC / Pseudo-F等)

[我采用了Scipy curve_fit(func, xData, yData, **options)中检查的6个不同功能,并获得了与统计模型中所获得的结果进行比较的结果。

我的职能:

# exponential function with adidtional konstant
def func0(x,a,b,c):
    return c+a*np.exp(b*x)

# exponential function
def func1(x, a, b):
    return a*np.exp(b*x) 

# logarithmic function
def func2(x, a,b):
    return a*np.exp(x)+b

# # generalized logistic function
def func3(x, a, b, c, d, g):
    return ((a-d)/((1+((x/c)**b))**g))+d

def func4(x, a,b,c,d):
    return a/(1 + np.exp(-c * (x - d))) + b

# parabola function
def func5(x, a,b,c):
    return a*x**2+b*x+c

这些是结果: =“

但是当我尝试将它们适合统计模型时:

GOOD(相同的名称):

import statsmodels.formula.api as sm

# logarithmic function
def func2(x, a,b):
    return a*np.exp(x)+b

model = sm.ols(formula='Y ~ np.exp(x)', data=tmp_df)

               coef std err    t    P>|t|   [0.025  0.975]
Intercept   -0.4388 0.006   -69.890 0.000   -0.451  -0.426
np.exp(x)   0.4176  0.004   106.238 0.000   0.410   0.425

-------------------------------------------------------------
# parabola function
def func5(x, a,b,c):
    return a*x**2+b*x+c

model = sm.ols(formula='Y ~ x + I(x**2)', data=tmp_df)

            coef    std err     t   P>|t|   [0.025  0.975]
Intercept   0.1995  0.004   47.709  0.000   0.191   0.208
x          -0.7953  0.020   -39.745 0.000   -0.835  -0.756
I(x ** 2)   1.5475  0.021   74.036  0.000   1.506   1.588

stats模型参数中其余功能的语法应该是什么? formula=

# exponential function with adidtional konstant
def func0(x,a,b,c):
    return c+a*np.exp(b*x)

# exponential function
def func1(x, a, b):
    return a*np.exp(b*x) 

# # generalized logistic function
def func3(x, a, b, c, d, g):
    return ((a-d)/((1+((x/c)**b))**g))+d

def func4(x, a,b,c,d):
    return a/(1 + np.exp(-c * (x - d))) + b

我在状态模型中实现公式时遇到一些问题。 (我第一次使用它们)我发现它具有很强的统计背景:R2 / adj-R2 / AIC / BIC / Pseudo-F等)I ...

python scipy curve-fitting statsmodels
1个回答
0
投票

实际使用您编写的函数如何?

© www.soinside.com 2019 - 2024. All rights reserved.