prakharg24 commited on
Commit
c337048
·
verified ·
1 Parent(s): 6aece6e

Update my_pages/rashomon_effect.py

Browse files
Files changed (1) hide show
  1. my_pages/rashomon_effect.py +40 -32
my_pages/rashomon_effect.py CHANGED
@@ -10,7 +10,7 @@ def render():
10
  """
11
  <div style='text-align: center; font-size:18px; color:gray;'>
12
  Consider data about individuals who either paid their loans (green) or defaulted (red). <br>
13
- Which model out of the two will you choose to give loan applications? <br><br>
14
  </div>
15
  """,
16
  unsafe_allow_html=True
@@ -32,7 +32,7 @@ def render():
32
  colors = ['green' if label == 1 else 'red' for label in labels]
33
 
34
  # Function to plot scatter
35
- def plot_scatter(x, y, colors, title="", decision_boundary=None, boundary_type=None, highlight_point=None):
36
  fig, ax = plt.subplots(figsize=(2, 2))
37
  ax.scatter(x, y, c=colors, alpha=0.6)
38
  ax.set_xlabel("Annual Income")
@@ -45,13 +45,20 @@ def render():
45
  # Decision boundary
46
  if decision_boundary is not None:
47
  if boundary_type == "vertical":
48
- ax.axvline(decision_boundary, color='blue', linestyle='--')
49
- ax.fill_betweenx(np.arange(min(y), max(y)), decision_boundary, max(x), alpha=0.1, color='green')
50
- ax.fill_betweenx(np.arange(min(y), max(y)), min(x), decision_boundary, alpha=0.1, color='red')
51
  elif boundary_type == "horizontal":
52
- ax.axhline(decision_boundary, color='blue', linestyle='--')
53
- ax.fill_between(np.arange(min(x), max(x)), decision_boundary, max(y), alpha=0.1, color='green')
54
- ax.fill_between(np.arange(min(x), max(x)), min(y), decision_boundary, alpha=0.1, color='red')
 
 
 
 
 
 
 
55
 
56
  # Highlight specific point
57
  if highlight_point is not None:
@@ -69,31 +76,32 @@ def render():
69
  with col2:
70
  st.pyplot(plot_scatter(income, credit, colors, title="Original Data"))
71
 
72
- col1, col2, col3, col4 = st.columns([1, 1, 1, 1])
73
  with col2:
74
- st.pyplot(plot_scatter(income, credit, colors, title="Vertical Boundary",
75
- decision_boundary=55, boundary_type="vertical"))
76
- left_selected = st.button("Choose Vertical Boundary")
77
  with col3:
78
- st.pyplot(plot_scatter(income, credit, colors, title="Horizontal Boundary",
79
- decision_boundary=55, boundary_type="horizontal"))
80
- right_selected = st.button("Choose Horizontal Boundary")
 
 
81
 
82
- col1, col2, col3 = st.columns([1.5, 1, 1.5])
83
  # Show new individual based on selection
84
- if left_selected:
85
- new_point = (40, 80) # High credit score, low income
86
- with col2:
87
- st.pyplot(plot_scatter(income, credit, colors,
88
- title="Vertical Boundary + New Individual",
89
- decision_boundary=55, boundary_type="vertical",
90
- highlight_point=new_point))
91
- st.warning("This individual was rejected by your chosen model. Why not choose a model that helps them?")
92
- elif right_selected:
93
- new_point = (80, 40) # Low credit score, high income
94
- with col2:
95
- st.pyplot(plot_scatter(income, credit, colors,
96
- title="Horizontal Boundary + New Individual",
97
- decision_boundary=55, boundary_type="horizontal",
98
- highlight_point=new_point))
99
- st.warning("This individual was rejected by your chosen model. Why not choose a model that helps them?")
 
10
  """
11
  <div style='text-align: center; font-size:18px; color:gray;'>
12
  Consider data about individuals who either paid their loans (green) or defaulted (red). <br>
13
+ Which model out of the two will you choose to give loan applications? <br>
14
  </div>
15
  """,
16
  unsafe_allow_html=True
 
32
  colors = ['green' if label == 1 else 'red' for label in labels]
33
 
34
  # Function to plot scatter
35
+ def plot_scatter(x, y, colors, title="", boundary_type=None, highlight_point=None):
36
  fig, ax = plt.subplots(figsize=(2, 2))
37
  ax.scatter(x, y, c=colors, alpha=0.6)
38
  ax.set_xlabel("Annual Income")
 
45
  # Decision boundary
46
  if decision_boundary is not None:
47
  if boundary_type == "vertical":
48
+ ax.axvline(65, color='blue', linestyle='--')
49
+ ax.fill_betweenx(np.arange(min(y), max(y)), 65, max(x), alpha=0.1, color='green')
50
+ ax.fill_betweenx(np.arange(min(y), max(y)), min(x), 65, alpha=0.1, color='red')
51
  elif boundary_type == "horizontal":
52
+ ax.axhline(650, color='blue', linestyle='--')
53
+ ax.fill_between(np.arange(min(x), max(x)), 650, max(y), alpha=0.1, color='green')
54
+ ax.fill_between(np.arange(min(x), max(x)), min(y), 650, alpha=0.1, color='red')
55
+ elif boundary_type == "slant":
56
+ slope = -10.677966 # From (94, 350) and (35, 980)
57
+ intercept = 1353.7288
58
+ y_line = slope * x + intercept
59
+ ax.plot(x, y_line, color='blue', linestyle='--')
60
+ ax.fill_between(x, y_line, max(y), alpha=0.1, color='green')
61
+ ax.fill_between(x, min(y), y_line, alpha=0.1, color='red')
62
 
63
  # Highlight specific point
64
  if highlight_point is not None:
 
76
  with col2:
77
  st.pyplot(plot_scatter(income, credit, colors, title="Original Data"))
78
 
79
+ col1, col2, col3, col4, col5 = st.columns([0.5, 1, 1, 1, 0.5])
80
  with col2:
81
+ st.pyplot(plot_scatter(income, credit, colors, boundary_type="vertical"))
82
+ vertical_selected = st.button("Choose Model 1")
 
83
  with col3:
84
+ st.pyplot(plot_scatter(income, credit, colors, boundary_type="slant"))
85
+ slant_selected = st.button("Choose Model 2")
86
+ with col3:
87
+ st.pyplot(plot_scatter(income, credit, colors, boundary_type="horizontal"))
88
+ horizontal_selected = st.button("Choose Model 3")
89
 
90
+ # col1, col2, col3 = st.columns([1.5, 1, 1.5])
91
  # Show new individual based on selection
92
+ # if left_selected:
93
+ # new_point = (40, 80) # High credit score, low income
94
+ # with col2:
95
+ # st.pyplot(plot_scatter(income, credit, colors,
96
+ # title="Vertical Boundary + New Individual",
97
+ # boundary_type="vertical",
98
+ # highlight_point=new_point))
99
+ # st.warning("This individual was rejected by your chosen model. Why not choose a model that helps them?")
100
+ # elif right_selected:
101
+ # new_point = (80, 40) # Low credit score, high income
102
+ # with col2:
103
+ # st.pyplot(plot_scatter(income, credit, colors,
104
+ # title="Horizontal Boundary + New Individual",
105
+ # boundary_type="horizontal",
106
+ # highlight_point=new_point))
107
+ # st.warning("This individual was rejected by your chosen model. Why not choose a model that helps them?")