Spaces:
Build error
Build error
File size: 2,085 Bytes
7f0977b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
import plotly.express as px
import streamlit as st
import matplotlib.pyplot as plt
import numpy as np
def acceptance_rate_driven_threshold_graph(clf_prediction_prob_df_gbt, acc_rate_thresh_gbt):
figa = px.histogram(clf_prediction_prob_df_gbt["PROB_DEFAULT"])
figa.update_layout(
title="Acceptance Rate Threshold vs. Loans Accepted",
xaxis_title="Acceptance Rate Threshold",
yaxis_title="Loans Accepted",
)
figa.update_traces(marker_line_width=1, marker_line_color="white")
figa.add_vline(
x=acc_rate_thresh_gbt,
line_width=3,
line_dash="solid",
line_color="red",
)
st.plotly_chart(figa)
def recall_accuracy_threshold_tradeoff_fig(
widthsize,
heightsize,
threshold_list,
thresh_def_recalls_list,
thresh_nondef_recalls_list,
thresh_accs_list,
):
fig = plt.figure(figsize=(widthsize, heightsize))
plt.plot(threshold_list, thresh_def_recalls_list, label="Default Recall")
plt.plot(
threshold_list, thresh_nondef_recalls_list, label="Non-Default Recall"
)
plt.plot(threshold_list, thresh_accs_list, label="Model Accuracy")
plt.xlabel("Probability Threshold")
plt.ylabel("Score")
plt.xlim(0, 1)
plt.ylim(0, 1)
plt.legend()
plt.title("Recall and Accuracy Score Tradeoff with Probability Threshold")
plt.grid(False)
return fig
def acceptance_rate_threshold_fig(probability_default, acceptancerate, bins):
# Probability distribution
probability_stat_distribution = probability_default.describe()
# Acceptance rate threshold
acc_rate_thresh = np.quantile(probability_default, acceptancerate)
fig = plt.figure()
plt.hist(
probability_default,
color="blue",
bins=bins,
histtype="bar",
ec="white",
)
# Add a reference line to the plot for the threshold
plt.axvline(x=acc_rate_thresh, color="red")
plt.title("Acceptance Rate Thershold")
return (
fig,
probability_stat_distribution,
acc_rate_thresh,
)
|