1
試圖通過熊貓和statsmodels做邏輯迴歸。不知道爲什麼我得到一個錯誤或如何解決它。Python中的迴歸
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)
或使用配方功能'進口statsmodels.api爲smf'然後smf.logit(公式.. ) – user333700
已編輯。我不知道,謝謝! –
感謝Phillip提供了一個更正的答案。我的評論很快。我想寫'import statsmodels.formula.api as smf',它也可以訪問公式接口的快捷鍵,小寫函數。這些只是模型的'from_formula'方法的便利包裝,例如'sm.Logit.from_formula' – user333700