bikuser bikuser - 1 year ago 142
Python Question

polynomial regression model in python

As I understood, Regression equation can be calculated by this functions:

import statsmodels.formula.api as smf
fg = smf.ols(formula='X ~ Y', data=data).fit()

we can also calculate from numpy polyfit function.

numpy.polyfit(x, y, degree)

as we can change the degree in numpy polyfit.

In ols function we can also add other independent variables as given below:

fg = smf.ols(formula='X ~ Y+Y1+Y2', data=data).fit()

So my question can we change the order/degree of fit in ols function ?
or can we add another independent variables in numpy polyfit function?

Answer Source

In the case of the statsmodels ability that you mention, formulae are specified using the patsy language (see Thus, for instance, that first invocation that you used could instead have been the following.

fg = smf.ols(formula='X ~ Y + Y**2', data=data).fit()


fg = smf.ols(formula='X ~ log(Y)', data=data).fit()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download