cannot import name 'OLS' from 'statsmodels.formula.api'
Asked Answered
P

1

2

I have this code:

from statsmodels.formula.api import OLS

The error is as follows:

ImportError: cannot import name 'OLS' from 'statsmodels.formula.api'

I tried updating statsmodels, but it does not work

Pika answered 12/8, 2020 at 13:38 Comment(3)
import statsmodels.api as sm; sm.OLS ?Compunction
in fact, if I use that code, another error occurs: "DLL load failed:The specified module can not be found"Pika
DLL load failed usually means that at least one of statsmodels, numpy, scipy or pandas is not correctly installedDiscursive
R
3

The formula API always uses lower case since these are functions and not classes, and so you can use

from statsmodels.formula.api import ols

or the more canonical

import statsmodels.formula.api as smf
smf.ols("y ~ x", df)
Ramentum answered 12/8, 2020 at 16:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.