我正在关注statsmodels教程
配有OLS型号
formula = 'S ~ C(E) + C(M) + X'
lm = ols(formula, salary_table).fit()
print lm.summary()
Run Code Online (Sandbox Code Playgroud)
预测值通过以下方式提供:
lm.predict({'X' : [12], 'M' : [1], 'E' : [2]})
结果作为单值数组返回.
是否有一种方法可以返回statsmodels中预测值(预测区间)的置信区间?
谢谢.
我正在对两组数据 Y 和 X 执行 OLS。我使用 statsmodel.api.OLS。但是,无论我之前是否向 X 添加常量,我都发现了一些非常不同的结果。这是代码:
import statsmodels.api as sm
import numpy as np
mess = "SELECT .... FROM... WHERE ...."
data = np.array(db.extractData(mess))
Y = data[,:0]
X = data[,:1]
#Option1
res = sm.OLS(Y,X).fit().rsquared ---> will return 0.76
#Option2
X = sm.add_constant(X)
res = sm.OLS(Y,X).fit().rsquared ---> will return 0.06
Run Code Online (Sandbox Code Playgroud)
考虑到我是否添加常量的巨大差异,我认为我做错了什么。非常感谢你花时间陪伴。
有没有办法在Python中找到r置信区间?
在R我可以做类似的事情:
cor.test(m, h)
Pearson's product-moment correlation
data: m and h
t = 0.8974, df = 4, p-value = 0.4202
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.6022868 0.9164582
sample estimates:
cor
0.4093729
Run Code Online (Sandbox Code Playgroud)
在Python中我可以使用以下公式计算r(cor):
r,p = scipy.stats.pearsonr(df.age, df.pets)
Run Code Online (Sandbox Code Playgroud)
但这不会返回r置信区间.
我正在尝试使用python statsmodels进行样本预测.我不想仅仅预测训练集末尾的下一个x值,但我想一次预测一个值,并在预测时考虑实际值.换句话说,我想做滚动1期预测,但我不想每次都重新校准模型.我能找到的最近的帖子是:
但是,这使用ARMA而不是ARIMA.如何使用ARIMA实现这一目标还是有更好的方法?我知道我实际上可以拉动系数并自己应用函数但是在我的代码中我使用的ARIMA模型随着时间的推移是动态的,因此系数和滞后值的使用数量不是恒定的.任何帮助将不胜感激.
我想使用 Python Pandas 对时间序列数据执行格兰杰因果关系测试,我有两个问题。
(1) 我曾尝试使用该pandas.stats.var软件包,但似乎已弃用。有没有其他推荐的选择?
(2) 我很难解释包中VAR.granger_causality()函数的输出pandas.stats.var。我能找到的唯一参考是源代码中的一条评论:
Returns the f-stats and p-values from the Granger Causality Test.
If the data consists of columns x1, x2, x3, then we perform the
following regressions:
x1 ~ L(x2, x3)
x1 ~ L(x1, x3)
x1 ~ L(x1, x2)
The f-stats of these results are placed in the 'x1' column of the
returned DataFrame. We then repeat for x2, x3.
Returns
-------
Dict, where 'f-stat' returns the DataFrame …Run Code Online (Sandbox Code Playgroud) 我正在尝试对 Pandas Dataframes 运行面板回归:
目前我有两个数据框,每个数据框包含 52 行(日期)* 99 列(99 个股票):带有数据表示的 Markdown 文件
运行时:
est=sm.OLS(Stockslist,averages).fit()
est.summary()
Run Code Online (Sandbox Code Playgroud)
我得到 ValueError: 形状 (52,99) 和 (52,99) 未对齐:99 (dim 1) != 52 (dim 0)
有人可以指出我做错了什么吗?该模型只是 y(i,t)=x(i,t)+误差项,因此没有截距。但是我想在未来添加时间效果。
亲切的问候,杰伦
有没有办法通过参数或其他东西在逻辑模型中为逻辑回归模型设置l2-Penalty?我刚刚在文档中找到了l1-Penalty,但对于l2-Penalty却没有.
在Statsmodels中,我可以使用我的模型
import statsmodels.api as sm
X = np.array([22000, 13400, 47600, 7400, 12000, 32000, 28000, 31000, 69000, 48600])
y = np.array([0.62, 0.24, 0.89, 0.11, 0.18, 0.75, 0.54, 0.61, 0.92, 0.88])
X2 = sm.add_constant(X)
est = sm.OLS(y, X2)
est2 = est.fit()
Run Code Online (Sandbox Code Playgroud)
然后使用打印一个很好的摘要
print(est2.summary())
Run Code Online (Sandbox Code Playgroud)
并使用提取的东西,如p值
est2.pvalues
Run Code Online (Sandbox Code Playgroud)
但是在摘要中存在置信区间,我对如何提取这些置信区间感到迷茫,就像我对pvalues一样.
除了在摘要中看到它们,我怎样才能获得这些置信区间?
我想构建一个随机森林回归器来模拟计数数据(泊松分布)。默认的“mse”损失函数不适合这个问题。有没有办法定义自定义损失函数并将其传递给 Python 中的随机森林回归器(Sklearn 等)?
是否有任何实现可以在任何包中拟合 Python 中的计数数据?
statsmodels ×10
python ×7
pandas ×4
scipy ×2
statistics ×2
forecasting ×1
numpy ×1
poisson ×1
python-3.x ×1
r ×1
scikit-learn ×1
time-series ×1