请原谅我的无知。我想要做的就是在我的回归中添加一个平方项,而无需在我的数据框中定义新列。我正在使用 statsmodels.formula.api(作为 stats),因为格式类似于我更熟悉的 R。
hours_model = stats.ols(formula='act_hours ~ h_hours + C(month) + trend', data = df).fit()
Run Code Online (Sandbox Code Playgroud)
以上按预期工作。
hours_model = stats.ols(formula='act_hours ~ h_hours + h_hours**2 + C(month) + trend', data = df).fit()
Run Code Online (Sandbox Code Playgroud)
这省略了 h_hours**2 并返回与上一行相同的输出。
我也试过:h_hours^2、math.pow(h_hours,2) 和 poly(h_hours,2) 都抛出错误。
任何帮助,将不胜感激。