<jupyter_start><jupyter_text>Example: Credit Card DefaultWe have seem this example in class. Our task will be to perform logistic regression and interpret the results.---* Model the default (binary variable) using various predictors    * Model 1: default ~ balance    * Model 2: default ~ student    * Model 3: default ~ balance + income + student    * Discuss the results    * What can you say about the coefficient for student in Models 1 and 2? Could you explain it?    * Using Model 1, what is our estimated probability of default for someone with a balance of USD1000? How about USD2000?<jupyter_code>import pandas as pd
import statsmodels.api as sm
import pylab as pl
import numpy as np
df = pd.read_csv("default_data.csv", index_col=0)
df.head(10)
# add manually intercept
df['intercept'] = 1.0

# change categorical variables to numerical
df['default_num'] = np.where(df.default=='Yes', 1,0)
df['student_num'] = np.where(df.student=='Yes', 1,0)

display(df)
# default ~ balance
cols_to_keep = [ 'balance','intercept']
logit  = sm.Logit(df['default_num'], df[cols_to_keep])
result = logit.fit()
result.summary()
# default ~ balance
cols_to_keep = ['student_num','intercept']
logit  = sm.Logit(df['default_num'], df[cols_to_keep])
result = logit.fit()
result.summary()
# default ~ balance
cols_to_keep = ['balance','income','student_num','intercept']
logit  = sm.Logit(df['default_num'], df[cols_to_keep])
result = logit.fit()
result.summary()<jupyter_output>Optimization terminated successfully.
         Current function value: 0.078577
         Iterations 10
{'fraction_non_alphanumeric': 0.11614550095724314, 'fraction_numerical': 0.0204211869814933, 'mean_word_length': 5.077519379844961, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '493633', 'license': 'MIT', 'n_tokens_mistral': 507, 'n_tokens_neox': 471, 'n_words': 159, 'path': 'Week_5_Default_Lab_AA.ipynb', 'repo_name': 'abdulra4/Analytical-Statistics', 'size': '1567'}