Python for Finance: Part II: 6 Multivariate Regression Analysis
Multivariate Regressions
Yi = β0 + β1X1 + β2X2 + βiXi + εi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import numpy as np import pandas as pd from scipy import stats import statsmodels.api as sm import matplotlib.pyplot as plt data = pd.read_excel('[PATH]/Housing.xlsx') data // Multivariate Regression: // Independent Variables: "House Size (sq.ft.)", "Number of Rooms", "Year of Construction" X = data[['House Size (sq.ft.)', 'Number of Rooms', 'Year of Construction']] Y = data['House Price'] X1 = sm.add_constant(X) reg = sm.OLS(Y,X1).fit() reg.summary() // Independent Variables: 'House Size (sq.ft.)', 'Number of Rooms' X = data[['House Size (sq.ft.)', 'Number of Rooms']] Y = data['House Price'] X1 = sm.add_constant(X) reg = sm.OLS(Y, X1).fit() reg.summary() |