在statsmodels.formula.api中,类似于R方法,一个常量会自动添加到数据中,一个截距会在在statsmodels.api中,必须自己添加一个常量(请参见the documentation here)。尝试使用statsmodels.api中的add_constant
x1 = sm.add_constant(x1,prepend=True) #prepend=True表示常量放在第一行
在statsmodels.formula.api中,类似于R方法,一个常量会自动添加到数据中,一个截距会在在statsmodels.api中,必须自己添加一个常量(请参见the documentation here)。尝试使用statsmodels.api中的add_constant
x1 = sm.add_constant(x1,prepend=True) #prepend=True表示常量放在第一行