加权线性回归- R 到 Python - Statsmodels
Weighted Linear Regression- R to Python - Statsmodels
我正在尝试将 R 代码翻译成 Python 并且 运行 在尝试复制包含 'weights' 的 R lm{stats} 函数时遇到麻烦,允许权重在拟合过程中使用。
我的最终目标是使用 statsmodels 库在 Python 中简单地 运行 一个 加权线性回归 。
搜索我找到的 Statsmodels 问题 caseweights in linear models #743 and SUMM/ENH rare events, unbalanced sample, matching, weights #2701 这让我认为 Statsmodels 可能无法做到这一点。
是否可以在 Statsmodels 中为 GLM 模型添加权重,或者是否有更好的方法来 运行 python 中的加权线性回归?
WLS 具有线性模型的权重,其中权重被解释为结果统计的逆方差。
http://www.statsmodels.org/stable/generated/statsmodels.regression.linear_model.WLS.html
未发布版本的 statsmodels 具有 GLM 的频率权重,但没有方差权重。
在 http://www.statsmodels.org/dev/generated/statsmodels.genmod.generalized_linear_model.GLM.html
中查看 freq_weights
(有很多未解决的问题,可以扩展权重的类型并为其他模型添加权重,但目前还没有。)
我正在尝试将 R 代码翻译成 Python 并且 运行 在尝试复制包含 'weights' 的 R lm{stats} 函数时遇到麻烦,允许权重在拟合过程中使用。
我的最终目标是使用 statsmodels 库在 Python 中简单地 运行 一个 加权线性回归 。
搜索我找到的 Statsmodels 问题 caseweights in linear models #743 and SUMM/ENH rare events, unbalanced sample, matching, weights #2701 这让我认为 Statsmodels 可能无法做到这一点。
是否可以在 Statsmodels 中为 GLM 模型添加权重,或者是否有更好的方法来 运行 python 中的加权线性回归?
WLS 具有线性模型的权重,其中权重被解释为结果统计的逆方差。 http://www.statsmodels.org/stable/generated/statsmodels.regression.linear_model.WLS.html
未发布版本的 statsmodels 具有 GLM 的频率权重,但没有方差权重。 在 http://www.statsmodels.org/dev/generated/statsmodels.genmod.generalized_linear_model.GLM.html
中查看freq_weights
(有很多未解决的问题,可以扩展权重的类型并为其他模型添加权重,但目前还没有。)