# Can I transform a few features to polynomial in multi regression?

Let's say I have 3 features in my ols model as below.

model = sm.ols(formula='y ~ a + b + c', data=df)


Question 1. If I want to transform the feature 'a' as polynomial 3 degree, then should I just add I(a**2) and I(a**3)?

Question 2. What about if I want to transform the feature 'a' as 3 degree and the feature 'b' as 2 degree.

Thanks.

• Your question 1 sounds correct, and that same idea would apply to question 2. Polynomials usually have an offset term, and you should have one in this case. – James Phillips Sep 19 '19 at 10:36
• Thanks, James. Do you mean I should add one constant on exog as part of features? – Yohan Chung Sep 19 '19 at 22:33
• Yes. The docs at statsmodels.org/dev/generated/… discuss "hasconst" to let the software know that the formula includes a constant (offset) term on the Right Hand Side (RHS in the docs). – James Phillips Sep 19 '19 at 23:23
• Got it. Cheers! – Yohan Chung Sep 19 '19 at 23:44