<jupyter_start><jupyter_text>Building a Logistic Regression Create a logistic regression based on the bank data provided. The data is based on the marketing campaign efforts of a Portuguese banking institution. The classification goal is to predict if the client will subscribe a term deposit (variable y).Note that the first column of the dataset is the index.Source: [Moro et al., 2014] <NAME>, <NAME> and <NAME>. A Data-Driven Approach to Predict the Success of Bank Telemarketing. Decision Support Systems, Elsevier, 62:22-31, June 2014  Import the relevant libraries<jupyter_code>import pandas as pd
import statsmodels.api as sm
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()

# this part not be needed after the latests updates of the library
from scipy import stats
stats.chisqprob = lambda chisq, df: stats.chi2.sf(chisq, df)<jupyter_output><empty_output><jupyter_text>Load the data Load the ‘Example_bank_data.csv’ dataset.<jupyter_code>raw_data = pd.read_csv('Example_bank_data.csv')
raw_data<jupyter_output><empty_output><jupyter_text>We want to know whether the bank marketing strategy was successful, so we need to transform the outcome variable into 0s and 1s in order to perform a logistic regression.<jupyter_code># We make sure to create a copy of the data before we start altering it. Note that we don't change the original data we loaded.
data = raw_data.copy()

# Removes the index column that came with the data
data = data.drop(['Unnamed: 0'], axis = 1)

# We use the map function to change any 'yes' values to 1 and 'no' values to 0. 
data['y'] = data['y'].map({'yes':1, 'no':0})
data
# Check the descriptive statistics
data.describe()<jupyter_output><empty_output><jupyter_text>Declare the dependent and independent variables<jupyter_code>y = data['y']
x1 = data['duration']<jupyter_output><empty_output><jupyter_text>Simple Logistic Regression Run the regression and visualize it on a scatter plot (no need to plot the line).<jupyter_code>x = sm.add_constant(x1)
reg_log = sm.Logit(y,x)
results_log = reg_log.fit()

# Get the regression summary
results_log.summary()
# Create a scatter plot of x1 (Duration, no constant) and y (Subscribed)
plt.scatter(x1,y,color = 'C0')

# Don't forget to label your axes!
plt.xlabel('Duration', fontsize = 20)
plt.ylabel('Subscription', fontsize = 20)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0890671169269734, 'fraction_numerical': 0.013507809202195019, 'mean_word_length': 5.732954545454546, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '50225', 'license': 'Apache-2.0', 'n_tokens_mistral': 768, 'n_tokens_neox': 722, 'n_words': 288, 'path': '15 - Advanced Statistical Methods in Python/5_Logistic Regression/5_Bulding a Logistic Regression Exercise/Building a Logistic Regression - Solution.ipynb', 'repo_name': 'olayinka04/365-data-science-courses', 'size': '2374'}