Spaces:
Runtime error
Runtime error
Delete src/app.py
Browse files- src/app.py +0 -110
src/app.py
DELETED
@@ -1,110 +0,0 @@
|
|
1 |
-
import altair as alt
|
2 |
-
from experiment_terminator import ExperimentTerminator
|
3 |
-
import numpy as np
|
4 |
-
import pandas as pd
|
5 |
-
import streamlit as st
|
6 |
-
|
7 |
-
|
8 |
-
def analyze_experiment():
|
9 |
-
"""
|
10 |
-
Upon clicking the button, run the experiment analyzer and display all of the output. This even
|
11 |
-
displays a histogram and some Arnold images.
|
12 |
-
"""
|
13 |
-
|
14 |
-
exp_output = et.analyze_experiment(planned_trials_a,
|
15 |
-
planned_trials_b,
|
16 |
-
completed_trials_a,
|
17 |
-
completed_trials_b,
|
18 |
-
successes_a,
|
19 |
-
successes_b)
|
20 |
-
|
21 |
-
# Only display the parameter summary information after the analysis has concluded.
|
22 |
-
input_summary.markdown(input_display)
|
23 |
-
|
24 |
-
# Display the summary statistics about the posterior distribution and posterior predictive
|
25 |
-
# distribution
|
26 |
-
output_col1.metric("Observed Conversion Rate in Control Group", value=np.round(exp_output[0], 4))
|
27 |
-
output_col2.metric("Observed Conversion Rate in Test Group", value=np.round(exp_output[1], 4))
|
28 |
-
output_col3.metric("Estimated Lift (Posterior Mean)", value=str(np.round(100 * exp_output[2], 2)) + "%")
|
29 |
-
output_col4.metric("Probability Test Rate > Control Rate", value=np.round(exp_output[3], 4))
|
30 |
-
output_col5.metric("Probability of Significance at Experiment End", value=np.round(exp_output[4], 4))
|
31 |
-
|
32 |
-
# Apply logic determining what conclusion is reached.
|
33 |
-
if exp_output[4] < 0.01 or exp_output[4] > .99: # We know the future of the experiment - conclude.
|
34 |
-
outstring = "## Experiment can be terminated. "
|
35 |
-
if exp_output[4] < .01: # The future is that there is almost no way we'll see significance
|
36 |
-
outstring += "No difference between experiment and control will be found."
|
37 |
-
else: # The future is that we almost certainly will see significance
|
38 |
-
if exp_output[3] > .5:
|
39 |
-
outstring += "Test is superior to control."
|
40 |
-
else:
|
41 |
-
outstring += "Control is superior to test."
|
42 |
-
conclusion_container.markdown(outstring)
|
43 |
-
|
44 |
-
# Add an Arnold image to drive home the point.
|
45 |
-
graph_col1.image('images/terminator_okay.gif', use_column_width=True)
|
46 |
-
else:
|
47 |
-
# We don't know the future of the experiment. Continue
|
48 |
-
conclusion_container.markdown("## Experiment should not be terminated.")
|
49 |
-
# Add an Arnold image to drive home the point.
|
50 |
-
graph_col1.image('images/thou_shalt_not_terminate.jpeg', use_column_width=True)
|
51 |
-
|
52 |
-
# Create the histogram showing the posterior distribution of lifts.
|
53 |
-
chart_data = pd.DataFrame({'lift': exp_output[5]})
|
54 |
-
chart = alt.Chart(chart_data).mark_bar().encode(
|
55 |
-
alt.X("lift", bin=alt.Bin(maxbins=30)),
|
56 |
-
y="count()"
|
57 |
-
).properties(title="Histogram of Posterior Distribution of Lift")
|
58 |
-
graph_col2.altair_chart(chart, use_container_width=True)
|
59 |
-
|
60 |
-
et = ExperimentTerminator()
|
61 |
-
|
62 |
-
# Set overall page configuration variables
|
63 |
-
st.set_page_config(layout="wide")
|
64 |
-
st.title('Experiment Terminator')
|
65 |
-
|
66 |
-
# Create the container where users can input information about their experiment.
|
67 |
-
main_container = st.container()
|
68 |
-
|
69 |
-
# Create input boxes in two columns, one for Control and one for Test. For each one,
|
70 |
-
# make input boxes for planned number of trials, completed trials, and successes.
|
71 |
-
col1, col2 = main_container.columns(2)
|
72 |
-
col1.header("Control")
|
73 |
-
planned_trials_a = col1.number_input("Planned Number of Trials", min_value=100, key='planned_trials_a', value=500)
|
74 |
-
completed_trials_a = col1.number_input("Completed Trials", min_value=100, max_value=planned_trials_a, key='completed_trials_a', value=300)
|
75 |
-
successes_a = col1.number_input("Successes", min_value=0, key='successes_a', value=25)
|
76 |
-
|
77 |
-
col2.header("Test")
|
78 |
-
planned_trials_b = col2.number_input("Planned Number of Trials", min_value=100, key='planned_trials_b', value=500)
|
79 |
-
completed_trials_b = col2.number_input("Completed Trials", min_value=100, max_value=planned_trials_b, key='completed_trials_b', value=300)
|
80 |
-
successes_b = col2.number_input("Successes", min_value=0, key='successes_b', value=35)
|
81 |
-
|
82 |
-
# Add a button to click to make the analysis run.
|
83 |
-
analyze = st.button("Analyze Experiment for Termination", on_click=analyze_experiment)
|
84 |
-
|
85 |
-
# Add a container to holds summary information on the parameters used to run the analysis. This gets
|
86 |
-
# displayed back to the user so they know what information the code is using.
|
87 |
-
input_summary = st.container()
|
88 |
-
input_display = "Analysis run with the following parameters: Control Group ("
|
89 |
-
input_display += str(planned_trials_a) + " planned trials, "
|
90 |
-
input_display += str(completed_trials_a) + " completed trials, "
|
91 |
-
input_display += str(successes_a) + " successes), Test Group ("
|
92 |
-
input_display += str(planned_trials_b) + " planned trials, "
|
93 |
-
input_display += str(completed_trials_b) + " completed trials, "
|
94 |
-
input_display += str(successes_b) + " successes)"
|
95 |
-
input_summary.markdown("")
|
96 |
-
|
97 |
-
# Add a container to hold summary statistics about the posterior distribution and posterior
|
98 |
-
# predictive distribution.
|
99 |
-
result_container = st.container()
|
100 |
-
output_col1, output_col2, output_col3, output_col4, output_col5 = result_container.columns(5)
|
101 |
-
|
102 |
-
# Add a container with a text statement about the conclusions reached.
|
103 |
-
conclusion_container = st.container()
|
104 |
-
conclusion_container.markdown("")
|
105 |
-
|
106 |
-
# Add a container to hold graphiics. This will hold an Arnold graphic on the left and a histogram on the right.
|
107 |
-
graph_container = st.container()
|
108 |
-
graph_col1, graph_col2 = graph_container.columns(2)
|
109 |
-
graph_col1.markdown("")
|
110 |
-
graph_col2.markdown("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|