Created
May 25, 2019 11:49
-
-
Save karamanbk/9a06a7a8c008dcb1f71358e478cc25c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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