Skip to content

Instantly share code, notes, and snippets.

@stealthbomber10
Created February 24, 2019 22:22
Show Gist options
  • Save stealthbomber10/ed665ec17543d742f5fef27fe16cd354 to your computer and use it in GitHub Desktop.
Save stealthbomber10/ed665ec17543d742f5fef27fe16cd354 to your computer and use it in GitHub Desktop.
linear regression help for jp
from xlrd import open_workbook
import numpy as np
import statsmodels.api as sm
'''
HOW TO RUN
Make sure FILE_NAME matches the name of the spreadsheet (change any spaces to underscores).
Make sure DEPEDENT_VAR_COL_NUMBER is set to the number of the column where your depedent variable is.
Make sure the spreadsheet file and this file are both on your desktop.
Open up a terminal and run the following:
cd ~/Desktop/; python3 reg.py
'''
FILE_NAME = "Reg_5.0.xlsx"
DEPENDENT_VAR_COL_NUMBER = 5
with open_workbook(FILE_NAME) as nfl_workbook:
team_stats = nfl_workbook.sheet_by_index(0)
x = [team_stats.col_values(i)[1:] for i in range(DEPENDENT_VAR_COL_NUMBER,team_stats.ncols)]
y = team_stats.col_values(DEPENDENT_VAR_COL_NUMBER-1)[1:]
x = np.array(x).T
x = sm.add_constant(x)
results = sm.OLS(endog=y, exog=x).fit()
print(results.summary())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment