Last active
August 11, 2017 03:38
-
-
Save dsal1951/87758964d97ad7eb8652e1013410f994 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
#Observations where y=1 | |
total_converts = df['CONVERT_ACTUAL'].sum() | |
#Total Observations | |
total_leads = df.index.size | |
baseline_convert_prob = total_converts/float(total_leads) | |
#Calculate Index of Positive Outcome Rate in Each Decile to the Baseline Positive Rate | |
lift_df['LIFT_INDEX'] = (lift_df['lift']/baseline_convert_prob)*100 | |
#Add Baseling Positive Rate to DataFrame | |
lift_df['BASELINE_CONVERT_PROB'] = baseline_convert_prob | |
""" | |
Plotting | |
""" | |
#Configure Grid | |
fig = plt.figure(figsize=(12,6)) | |
gs = gridspec.GridSpec(2,1) | |
ax1 = plt.subplot(gs[0,0]) | |
#Calculate Percent of Total Leads Pursued for x-axis tick labels | |
lift_df['CUM_LEADS'] = lift_df['LEADS_COUNT'].cumsum()/lift_df['LEADS_COUNT'].sum() | |
ax1.plot(lift_plot_data['CUM_LEADS'], | |
lift_plot_data['LIFT_INDEX'], | |
color='g', label='Classifier Performance') | |
ax1.axhline(100,linestyle='dashed', | |
color='r',label="Baseline Performance") | |
ax1.fill_between(lift_plot_data['CUM_LEADS'], | |
lift_plot_data['LIFT_INDEX'], | |
100,where=lift_plot_data['LIFT_INDEX']>=100, | |
interpolate=True,color='g',alpha=0.25) | |
#Configure x-axis | |
ax1.set_xticks(np.linspace(0,1,6)) | |
x1_vals = ax1.get_yticks() | |
ax1.set_xticklabels(['{:3.0f}%'.format(val*100) for val in x1_vals]) | |
#Configure y-axis | |
ax1.set_ylim(top=1000) | |
y1_vals = ax1.get_yticks() | |
ax1.set_yticklabels(['{:,.0f}x'.format(val/100) for val in y1_vals]) | |
ax1.set_ylabel("Upgrade Lift Index") | |
ax1.legend(loc='center right',frameon=True) | |
ax1.set_title("Lift Chart") | |
gs.tight_layout(fig) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment