Topic : Predict if Client will subscribe to direct marketing campaign for a banking institution
Summary : The data is related with direct marketing campaigns of a Portuguese banking institution. The marketing campaigns were based on phone calls. Often, more than one contact to the same client was required, in order to access if the product (bank term deposit) would be ('yes') or not ('no') subscribed.
df_y = df['y'].value_counts()
print 'Percentage of Y=yes:',(df_y[1] / float(df_y[0] + df_y[1])) * 100
sns.countplot(df['y'])
plt.show()
Last Contact month of year (categorical: 'jan', 'feb', 'mar', ..., 'nov', 'dec')
#Distribution of variable month
plt.figure(figsize=(15,5))
plt.subplot(1,2,1)
sns.countplot(df['month'])
plt.title('Bar Graph showing distribution of Calls made across various months')
plt.subplot(1,2,2)
sns.countplot(x="month", hue="y", data=df);
plt.title('Graph showing distribution of Calls made along with Convertion results across various months')
plt.show()
df_months = pd.crosstab(index=df['month'],columns=df['y'])
df_months['percentage(yes)'] = (df_months['yes'] / (df_months['yes'] + df_months['no'])) * 100
df_months.head()
Last contact day of the week (categorical: 'mon','tue','wed','thu','fri')
plt.figure(figsize=(15,5))
plt.subplot(1,2,1)
sns.countplot(df['day_of_week'])
plt.title('Distribution of Calls made across various days of the week')
plt.subplot(1,2,2)
sns.countplot(x="day_of_week", hue="y", data=df);
plt.title('Distribution of Calls made along with Convertion results across various days of the week')
plt.show()
df_days = pd.crosstab(index=df['day_of_week'],columns=df['y'])
df_days['percentage(yes)'] = (df_days['yes'] / (df_days['yes'] + df_days['no'])) * 100
df_days.head()
last contact duration, in seconds (numeric). Important note: this attribute highly affects the output target (e.g., if duration=0 then y='no'). Yet, the duration is not known before a call is performed. Also, after the end of the call y is obviously known. Thus, this input should only be included for benchmark purposes and should be discarded if the intention is to have a realistic predictive model.
#Distribution of variable day of week
plt.figure(figsize=(15,10))
plt.subplot(1,2,1)
plt.hist(df['duration'],bins=[0,100,200,300,400,500,1000,1500,2000])
plt.title('Histogram of Call duration')
plt.xlim(0,2500)
plt.subplot(1,2,2)
sns.boxplot(x='y',y='duration',data=df)
plt.title('Distribution of Call duration(in secs) vs Subscribed')
plt.show()
df[df['duration'] == 0]
NOTE: We only have 4 datapoints with duration = 0 which means these people were contacted first time These 4 data points should be removed before model training, as the duration is not known
new_data = df[df['duration'] != 0]
#Let's see if there is still any trend in coversion based on duration after removing duration = 0, data points
plt.figure(figsize=(10,12))
sns.boxplot(x='y',y='duration',data=new_data)
plt.show()
Number of contacts performed during this campaign and for this client (numeric, includes last contact)
#Distribution of variable day of week
plt.figure(figsize=(15,10))
plt.subplot(1,2,1)
plt.hist(df['campaign'])
plt.title('Distribution of Calls made during a campaign')
camp_less_than_20 = df[df['campaign'] < 20]
plt.subplot(1,2,2)
sns.countplot(x="campaign", hue="y", data=camp_less_than_20);
plt.title('Distribution of Calls made during a campaign vs Subscribed')
plt.show()