gpt4 book ai didi

python - 使用 statsmodels.formula.api 中的 ols - 如何删除常数项?

转载 作者:太空宇宙 更新时间:2023-11-03 12:57:15 24 4
gpt4 key购买 nike

我正在关注 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()

最佳答案

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

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

关于python - 使用 statsmodels.formula.api 中的 ols - 如何删除常数项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36409889/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com