【问题标题】:using ols from statsmodels.formula.api - how to remove constant term?使用 statsmodels.formula.api 中的 ols - 如何删除常数项?
【发布时间】:2016-07-24 10:07:22
【问题描述】:

我正在关注statsmodels 教程中的第一个示例:

http://statsmodels.sourceforge.net/devel/

如何指定在 ols 中不使用常数项进行线性拟合?

# Fit regression model (using the natural log of one of the regressors)
results = smf.ols('Lottery ~ Literacy + np.log(Pop1831)', data=dat).fit()

【问题讨论】:

    标签: python numpy regression statsmodels patsy


    【解决方案1】:

    作为shown here in the section on Operators,您可以在公式字符串中使用“-1”来删除截取项:

    results = smf.ols('Lottery ~ Literacy + np.log(Pop1831) - 1', data=dat).fit()
    

    【讨论】:

    • 另一种选择是在公式中添加零。
    猜你喜欢
    • 2019-10-20
    • 1970-01-01
    • 2020-03-16
    • 1970-01-01
    • 2016-12-21
    • 2021-12-16
    • 2021-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多