Skip to content

Instantly share code, notes, and snippets.

@akeaswaran
Last active May 8, 2020 00:05
Show Gist options
  • Save akeaswaran/3a801dddb608c2556b29e4fd53cc1351 to your computer and use it in GitHub Desktop.
Save akeaswaran/3a801dddb608c2556b29e4fd53cc1351 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding: utf-8
# module imports
from patsy import dmatrices
import pandas as pd
from sklearn.linear_model import LogisticRegression
import statsmodels.discrete.discrete_model as sm
# read in the data & create matrices
df = pd.read_csv("./epa_base_data.csv")
df = df[df.year == 2019]
y, X = dmatrices('drive_point ~ C(down) + distance + adjusted_yardline + C(down):distance + C(down):adjusted_yardline + period + margin', df, return_type='dataframe')
# sklearn output
model = LogisticRegression(multi_class='multinomial', solver='newton-cg', C=1000000,fit_intercept=False)
mdl = model.fit(X, y)
model.coef_
# sm
logit = sm.MNLogit(y, X)
logit.fit(method="ncg").params
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment