Skip to content

Instantly share code, notes, and snippets.

@karamanbk
Created May 25, 2019 11:49
Show Gist options
  • Save karamanbk/9a06a7a8c008dcb1f71358e478cc25c1 to your computer and use it in GitHub Desktop.
Save karamanbk/9a06a7a8c008dcb1f71358e478cc25c1 to your computer and use it in GitHub Desktop.
#preparing column names for the model
all_columns = []
for column in df_data.columns:
column = column.replace(" ", "_").replace("(", "_").replace(")", "_").replace("-", "_")
all_columns.append(column)
df_data.columns = all_columns
glm_columns = 'gender'
for column in df_data.columns:
if column not in ['Churn','customerID','gender']:
glm_columns = glm_columns + ' + ' + column
#import libraries
import statsmodels.api as sm
import statsmodels.formula.api as smf
#fit the model
glm_model = smf.glm(formula='Churn ~ {}'.format(glm_columns), data=df_data, family=sm.families.Binomial())
res = glm_model.fit()
#print the summary
print(res.summary())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment