prakharg24 commited on
Commit
221e0dd
·
verified ·
1 Parent(s): 898dd74

Create rashomon_developer.py

Browse files
Files changed (1) hide show
  1. my_pages/rashomon_developer.py +81 -0
my_pages/rashomon_developer.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import matplotlib.pyplot as plt
3
+ import numpy as np
4
+ from utils import add_navigation, add_instruction_text
5
+ from rashomon_effect import plot_scatter
6
+ from rashomon_effect import income, credit, labels, colors
7
+
8
+ plt.style.use('dark_background')
9
+
10
+ def render():
11
+ add_navigation("txt_rashomon_effect", "txt_developer_decisions")
12
+
13
+ add_instruction_text(
14
+ """
15
+ Consider the following data about individuals who did (green) or didn't (red) repay their loans. <br>
16
+ Which model out of these three will you choose to judge loan applications?
17
+ """
18
+ )
19
+
20
+ #### Rashomon Set Definition
21
+ rashomon_set_message = """
22
+ Multiple models achieving similar accuracy, i.e., multiple interpretations of the data, is known as the Rashomon effect.
23
+ We call the models below part of a 'Rashomon set'.
24
+ """
25
+ st.markdown(
26
+ f"<div style='text-align:center; color:#c0392b; font-size:20px; margin:0 0;'>{rashomon_set_message}</div>",
27
+ unsafe_allow_html=True,
28
+ )
29
+
30
+ #### Plot three graphs to represent three models
31
+ graph_selected, highlight_point = None, None
32
+ if "graph_selected" in st.session_state:
33
+ graph_selected = st.session_state.graph_selected
34
+ highlight_point = st.session_state.highlight_point
35
+
36
+ col1, col2, col3, col4, col5 = st.columns([0.5, 1, 1, 1, 0.5])
37
+ with col2:
38
+ st.pyplot(plot_scatter(income, credit, colors, boundary_type="vertical", highlight_point=highlight_point))
39
+ st.markdown("Accuracy: 90%")
40
+ if graph_selected=="vertical":
41
+ button_click_v = st.button("Choose Model 1", type="primary")
42
+ else:
43
+ button_click_v = st.button("Choose Model 1")
44
+ if button_click_v:
45
+ st.session_state.highlight_point = (32, 902)
46
+ st.session_state.graph_selected = "vertical"
47
+ st.rerun()
48
+ with col3:
49
+ st.pyplot(plot_scatter(income, credit, colors, boundary_type="slant", highlight_point=highlight_point))
50
+ st.markdown("Accuracy: 90%")
51
+ if graph_selected=="slant":
52
+ button_click_s = st.button("Choose Model 2", type="primary")
53
+ else:
54
+ button_click_s = st.button("Choose Model 2")
55
+ if button_click_s:
56
+ st.session_state.highlight_point = (32, 902)
57
+ st.session_state.graph_selected = "slant"
58
+ st.rerun()
59
+ with col4:
60
+ st.pyplot(plot_scatter(income, credit, colors, boundary_type="horizontal", highlight_point=highlight_point))
61
+ st.markdown("Accuracy: 90%")
62
+ if graph_selected=="horizontal":
63
+ button_click_h = st.button("Choose Model 3", type="primary")
64
+ else:
65
+ button_click_h = st.button("Choose Model 3")
66
+ if button_click_h:
67
+ st.session_state.highlight_point = (97, 370)
68
+ st.session_state.graph_selected = "horizontal"
69
+ st.rerun()
70
+
71
+ #### Multiplicity Definition
72
+ if "graph_selected" in st.session_state:
73
+ multiplicity_message = """
74
+ Because of your choice, the highlighted individual was rejected, but would have gotten loan under a different model.
75
+ These conflicting predictions is multiplicity.<br><br>
76
+ <b>Clearly, the choice of model directly impacts individuals!</b>
77
+ """
78
+ st.markdown(
79
+ f"<div style='text-align:center; color:#c0392b; font-size:20px; margin:0;'>{multiplicity_message}</div>",
80
+ unsafe_allow_html=True,
81
+ )