我在模型拟合方面的知识有限,在时间序列数据集上拟合
python
中的模型时遇到问题。这是我的数据示例:
我能够将
Muliple linear regression model
放入我的数据中:
y = ax1 + bx2 + c
但是,
R Squared
值低于50%。我想要一个更强大但简单的模型。通常,我所在领域的先前文献在模型中使用指数项和线性项的组合来拟合此类数据,例如:
y = a*exp(-x1) + b*x2 + c
我已经尝试了
Generalized Linear Model (GLM)
中的 statsmodels
假设 Poisson
分布如下:
import pandas as pd
import statsmodels.api as sm
df = pd.read_csv("G:\Sample.csv") # G:\ for file location
# defining independent and dependent variables
X = df[['x1','x2']]
y = df['y']
# Model
model = sm.GLM(y, X,family=sm.families.Poisson())
results = model.fit()
print(results.summary())
然而,这不是我想要的模型:
即
y = a*exp(-x1) + b*x2 + c
我非常感谢您的帮助!
谢谢!
为什么不直接将
x1
转换为 np.exp(-x1)
?
X = np.c_[np.exp(-df['x1']), df['x2']]
y = df['y']
model = sm.GLM(y, X,family=sm.families.Poisson())
results = model.fit()
print(results.summary())