Skip to content
Advertisement

Can I use numpy.polyfit(x, y, deg) for multiple linear regression

Is there any way I can fit two independent variables and one dependent variable in numpy.polyfit()?

I have a panda data frame that I loaded from a csv file. I wish to include two columns as independent variables to run multiple linear regression using NumPy.

Currently my simple linear regression looks like this:

model_combined = np.polyfit(data.Exercise, y, 1)

I wish to include data.Age in x as well.

Advertisement

Answer

Assuming your equation is a * exercise + b * age + intercept = y, you can fit a multiple linear regression with numpy or scikit-learn as follows:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement