我正在尝试在著名的 iris 数据集上使用 statsmodels 的 MNLogit 函数。当我尝试拟合模型时,我得到:“当前函数值:nan”。这是我正在使用的代码:
import statsmodels.api as st
iris = st.datasets.get_rdataset('iris','datasets')
y = iris.data.Species
x = iris.data.ix[:, 0:4]
x = st.add_constant(x, prepend = False)
mdl = st.MNLogit(y, x)
mdl_fit = mdl.fit()
print (mdl_fit.summary())
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用seasonal_decompose 来分解我的时间序列。数据是完美的时间序列,频率为“2T”,即 2 分钟。在文件 tsatools.py (site-pkgs\statsmodels\tsa\tsatools.py) 的第 655 行中,我添加了以下内容。_ elif freq == 'T': return 6024752_ 我从以下推论中添加了这一点: Freq A 表示 1 年,因此返回 1。Q 表示每季度一次,因此返回 4 M 表示每月一次,因此返回 12,依此类推。因此,T 表示每分钟,因此 60247*365
当我执行上述操作时,出现以下错误:ValueError: Inferred frequency of index and frequency 不匹配。此函数不会从 season.py (statsmodel\tsa\seasonal.py) 中的第 70 行重新采样,因为:变量 freq 是:<2 * Minutes> 变量 pfreq 是 2T 524160。
我的意思是季节性分解应该能够分解 1 分钟频率的时间序列,并且似乎发生了一些变化。请看看它,如果我遗漏了什么,请告诉我。
我目前正在使用from pandas.stats.plm import PanelOLS运行面板回归。我需要切换到 statsmodel 以便我可以输出异方差稳健的结果。我一直无法找到有关为 statsmodel 调用面板回归的符号。总的来说,我发现 statsmodel 的文档不是很用户友好。有人熟悉 statsmodel 中的面板回归语法吗?
我想知道如何从 python statsmodels 中拟合的逻辑回归模型中获得优势比。
>>> import statsmodels.api as sm
>>> import numpy as np
>>> X = np.random.normal(0, 1, (100, 3))
>>> y = np.random.choice([0, 1], 100)
>>> res = sm.Logit(y, X).fit()
Optimization terminated successfully.
Current function value: 0.683158
Iterations 4
>>> res.summary()
<class 'statsmodels.iolib.summary.Summary'>
"""
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 100
Model: Logit Df Residuals: 97
Method: MLE Df Model: 2
Date: Sun, 05 Jun 2016 Pseudo R-squ.: 0.009835
Time: 23:25:06 Log-Likelihood: -68.316
converged: True …Run Code Online (Sandbox Code Playgroud) 我使用以下方法训练了逻辑模型,来自乳腺癌数据,并且仅使用了一个特征“mean_area”
from statsmodels.formula.api import logit
logistic_model = logit('target ~ mean_area',breast)
result = logistic_model.fit()
Run Code Online (Sandbox Code Playgroud)
在训练好的模型中有一个内置的预测方法。然而,这给出了所有训练样本的预测值。如下
predictions = result.predict()
Run Code Online (Sandbox Code Playgroud)
假设我想要一个新值的预测,比如 30 我如何使用经过训练的模型来输出值?(而不是手动读取系数和计算)
python machine-learning scikit-learn statsmodels logistic-regression
I am trying to model a time series in python using python 2.7.11 and the excellent statsmodels.tsa package. My data consists of hourly measurements of traffic intensity over several weeks. Thus, the data has multiple seasonal components, days form a 24 hour period; weeks form a 168 hour period.
At this point, the modeling options in statsmodels.tsa are not set up to handle multiple seasonality, as they only allow for the specification of one seasonal factor. However, I came across …
import statsmodels.api as sm
xdat = rets['EUROSTOXX']
xdat = sm.add_constant(xdat)
ydat = rets['VSTOXX']
model = sm.OLS(y=ydat,x=xdat).fit()
Run Code Online (Sandbox Code Playgroud)
我不明白为什么会出现该主题所述的错误。下面是rets的Dataframe的尾部
Out[105]:
EUROSTOXX VSTOXX
2014-12-23 0.011835 -0.039307
2014-12-24 -0.002449 0.000000
2014-12-29 0.000160 0.121598
2014-12-30 -0.015574 0.048998
2014-12-31 0.003336 0.000000
Run Code Online (Sandbox Code Playgroud) File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\distutils\mingw
dry_run, force)
File "C:\ProgramData\Anaconda3\lib\distutils\cygwinccompiler.py", line
if self.ld_version >= "2.10.90":
TypeError: '>=' not supported between instances of 'NoneType' and 'str'
Run Code Online (Sandbox Code Playgroud)
长期以来在我的 python 环境中面临这个错误,我不知道是否由于 cygwinenter code here
运行 MixedLM 并希望将输出推送到 Excel 或 CSV,请参阅下面的模型代码和输出:
model = smf.mixedlm('y_var ~ gas_prices', dfModel,
groups = dfModel['region'])
mdf = model.fit()
print(mdf.summary())
Mixed Linear Model Regression Results
======================================================================
Model: MixedLM Dependent Variable: yVar
No. Observations: 420 Method: REML
No. Groups: 4 Scale: 45635645671.2271
Min. group size: 105 Likelihood: -5720.8133
Max. group size: 105 Converged: Yes
Mean group size: 105.0
----------------------------------------------------------------------
Coef. Std.Err. z P>|z| [0.025 0.975]
----------------------------------------------------------------------
Intercept 3241461.947 112718.823 28.757 0.000 3020537.112 3462386.781
gas_prices -118128.471 46931.809 -2.517 0.012 -210113.126 -26143.816
xVar2 275.017 …Run Code Online (Sandbox Code Playgroud) 基于这个问题在此处输入链接描述,我使用 statsmodels 在 python 中实现方差分析。我的数据在 Pandas DataFrame 中并且country是一个分类变量。
def anova(data):
mod = ols('C(country) ~ playerRank+playerGames', data=data).fit()
aov_table = sm.stats.anova_lm(mod, typ=2)
print aov_table
Run Code Online (Sandbox Code Playgroud)
当我使用上述功能时,它显示:
File "<ipython-input-32-e77ae8a55692>", line 1, in <module>
aov_table = sm.stats.anova_lm(mod, typ=2)
File "C:\ProgramData\Anaconda2\lib\site-packages\statsmodels\stats\anova.py", line 326, in anova_lm
return anova_single(model, **kwargs)
File "C:\ProgramData\Anaconda2\lib\site-packages\statsmodels\stats\anova.py", line 83, in anova_single
robust)
File "C:\ProgramData\Anaconda2\lib\site-packages\statsmodels\stats\anova.py", line 178, in anova2_lm_single
cov = _get_covariance(model, None)
File "C:\ProgramData\Anaconda2\lib\site-packages\statsmodels\stats\anova.py", line 15, in _get_covariance
return model.cov_params()
File "C:\ProgramData\Anaconda2\lib\site-packages\statsmodels\base\wrapper.py", line 95, in wrapper
obj = data.wrap_output(func(results, …Run Code Online (Sandbox Code Playgroud) python ×10
statsmodels ×10
pandas ×2
python-3.x ×2
time-series ×2
anova ×1
charts ×1
cygwin ×1
dataframe ×1
scikit-learn ×1