import statsmodels.formula.api as sm
import numpy as np
import pandas
url = "http://vincentarelbundock.github.com/Rdatasets/csv/HistData/Guerry.csv"
df = pandas.read_csv(url)
df = df[['Lottery', 'Literacy', 'Wealth', 'Region']].dropna()
print df.head()
mod = sm.ols(formula='Lottery ~ Literacy + Wealth + Region', data=df)
res = mod.fit()
print res.summary()
打印表格后吐回这个错误。
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-f69caff21ed0> in <module>()
6 df = df[['Lottery', 'Literacy', 'Wealth', 'Region']].dropna()
7 print df.head()
----> 8 mod = sm.ols(formula='Lottery ~ Literacy + Wealth + Region', data=df)
9 res = mod.fit()
10 print res.summary()
TypeError: from_formula() takes at least 3 arguments (2 given)
这似乎不是可接受的行为。我究竟做错了什么?