- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在 OLS 形式的 StatsModels 中,results.summary 显示回归结果的汇总(例如 AIC、BIC、R 平方、...)
有什么办法可以在 sklearn.linear_model.ridge 中得到这个汇总表吗?
如果有人能指导我,我将不胜感激。谢谢。
最佳答案
据我所知,sklearn 中没有类似 R(或 Statsmodels)的汇总表。 (请勾选this answer)
相反,如果您需要它,可以使用 statsmodels.regression.linear_model.OLS.fit_regularized类(class)。 (L1_wt=0
用于岭回归。)
目前,似乎 model.fit_regularized(~).summary()
返回 None
尽管有下面的文档字符串。但是对象有params
,summary()
可以不知何故使用。
Returns: A RegressionResults object, of the same type returned by
fit
.
示例。
样本数据不适用于岭回归,但无论如何我都会尝试。
在.
import numpy as np
import pandas as pd
import statsmodels
import statsmodels.api as sm
import matplotlib.pyplot as plt
statsmodels.__version__
出去。
'0.8.0rc1'
在.
data = sm.datasets.ccard.load()
print "endog: " + data.endog_name
print "exog: " + ', '.join(data.exog_name)
data.exog[:5, :]
出去。
endog: AVGEXP
exog: AGE, INCOME, INCOMESQ, OWNRENT
Out[2]:
array([[ 38. , 4.52 , 20.4304, 1. ],
[ 33. , 2.42 , 5.8564, 0. ],
[ 34. , 4.5 , 20.25 , 1. ],
[ 31. , 2.54 , 6.4516, 0. ],
[ 32. , 9.79 , 95.8441, 1. ]])
在.
y, X = data.endog, data.exog
model = sm.OLS(y, X)
results_fu = model.fit()
print results_fu.summary()
出去。
OLS Regression Results
==============================================================================
Dep. Variable: y R-squared: 0.543
Model: OLS Adj. R-squared: 0.516
Method: Least Squares F-statistic: 20.22
Date: Wed, 19 Oct 2016 Prob (F-statistic): 5.24e-11
Time: 17:22:48 Log-Likelihood: -507.24
No. Observations: 72 AIC: 1022.
Df Residuals: 68 BIC: 1032.
Df Model: 4
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------
x1 -6.8112 4.551 -1.497 0.139 -15.892 2.270
x2 175.8245 63.743 2.758 0.007 48.628 303.021
x3 -9.7235 6.030 -1.613 0.111 -21.756 2.309
x4 54.7496 80.044 0.684 0.496 -104.977 214.476
==============================================================================
Omnibus: 76.325 Durbin-Watson: 1.692
Prob(Omnibus): 0.000 Jarque-Bera (JB): 649.447
Skew: 3.194 Prob(JB): 9.42e-142
Kurtosis: 16.255 Cond. No. 87.5
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
在.
frames = []
for n in np.arange(0, 0.25, 0.05).tolist():
results_fr = model.fit_regularized(L1_wt=0, alpha=n, start_params=results_fu.params)
results_fr_fit = sm.regression.linear_model.OLSResults(model,
results_fr.params,
model.normalized_cov_params)
frames.append(np.append(results_fr.params, results_fr_fit.ssr))
df = pd.DataFrame(frames, columns=data.exog_name + ['ssr*'])
df.index=np.arange(0, 0.25, 0.05).tolist()
df.index.name = 'alpha*'
df.T
出去。
在.
%matplotlib inline
fig, ax = plt.subplots(1, 2, figsize=(14, 4))
ax[0] = df.iloc[:, :-1].plot(ax=ax[0])
ax[0].set_title('Coefficient')
ax[1] = df.iloc[:, -1].plot(ax=ax[1])
ax[1].set_title('SSR')
出去。
在.
results_fr = model.fit_regularized(L1_wt=0, alpha=0.04, start_params=results_fu.params)
final = sm.regression.linear_model.OLSResults(model,
results_fr.params,
model.normalized_cov_params)
print final.summary()
出去。
OLS Regression Results
==============================================================================
Dep. Variable: y R-squared: 0.543
Model: OLS Adj. R-squared: 0.516
Method: Least Squares F-statistic: 20.17
Date: Wed, 19 Oct 2016 Prob (F-statistic): 5.46e-11
Time: 17:22:49 Log-Likelihood: -507.28
No. Observations: 72 AIC: 1023.
Df Residuals: 68 BIC: 1032.
Df Model: 4
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------
x1 -5.6375 4.554 -1.238 0.220 -14.724 3.449
x2 159.1412 63.781 2.495 0.015 31.867 286.415
x3 -8.1360 6.034 -1.348 0.182 -20.176 3.904
x4 44.2597 80.093 0.553 0.582 -115.564 204.083
==============================================================================
Omnibus: 76.819 Durbin-Watson: 1.694
Prob(Omnibus): 0.000 Jarque-Bera (JB): 658.948
Skew: 3.220 Prob(JB): 8.15e-144
Kurtosis: 16.348 Cond. No. 87.5
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
关于python - sklearn.linear_model.ridge 中的统计汇总表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40072870/
我的数据库中有 4 个表。 2012,2013,2014,2015. 每一个都是这样布置的: 我想对每年的每个 StartStation 求和: StartStation 2012
您建议使用哪种方法,为什么? 创建汇总表和 . . . 1) 实时更新表格。 2) 每 15 分钟运行一次 group by 查询以更新汇总表。 3) 还有别的吗? 数据必须接近实时,不能等一个小时、
我正在尝试使用来自 python 的 pandas 的 .describe() 创建一个汇总表。 我有以下数据框: df = pd.DataFrame({'Group':['Group1', 'Gro
我在 pandas 中得到了下表: x 是 1 1 2 3 2 5 2 4 1 4 1 5 我想看看变量x的模式,所以我想看看模式是什么。 在表格中,您会看到 x=1 然后 x=2 三次,然后返回
我有一个数据库,其中有许多具有关系的表中的数据 TABLE Cars (stock) --------------------- Model colourid Doors --------
我正在尝试对列表求和,但跳过第一个偶数,然后继续添加列表的其余部分,包括其余的偶数,但我似乎不太正确。 list = [-3, -7, -1, 0, 1, 2, 3, 4, 5, 6, 7] def
我正在开发一个我需要创建和维护的项目 汇总表 出于性能原因。我相信正确的术语是 物化 View . 我有两个主要原因这样做: 非规范化 我尽可能地对表格进行了标准化。所以在某些情况下,我必须加入许多表
我有两个表,表 A 有列 token(主键)和 停机时间(INT),表 B 有列 token, status(ENUM 有 3 种状态:active, unstable, inactive ), du
我正在使用包 purrr 和 broom 来生成一系列 glm 并构建一个包含模型信息的表格,以便我可以比较它们。 当我从 purrr 调用 map 函数时,代码失败。我认为问题与 mutate 和
我是一名优秀的程序员,十分优秀!