尝试通过pandas和stats模型进行logistic回归。不知道为什么我会犯错误或者怎么解决。
import pandas as pd
import statsmodels.api as sm
x = [1, 3, 5, 6, 8]
y = [0, 1, 0, 1, 1]
d = { "x": pd.Series(x), "y": pd.Series(y)}
df = pd.DataFrame(d)
model = "y ~ x"
glm = sm.Logit(model, df=df).fit()
错误:
Traceback (most recent call last):
File "regress.py", line 45, in <module>
glm = sm.Logit(model, df=df).fit()
TypeError: __init__() takes exactly 3 arguments (2 given)
不能将公式传递给
Logit
。做:这几乎是直接从the docs on how to do exactly what you're asking开始的。
编辑:您也可以使用公式API,如@user333700所建议的:
相关问题 更多 >
编程相关推荐