andrewicus commited on
Commit
3f2a671
Β·
verified Β·
1 Parent(s): f35e74d

Upload 5 files

Browse files
pages/03 πŸ§‘β€πŸ’» Explainable AI.py CHANGED
@@ -20,6 +20,8 @@ st.image(url, output_format="PNG", width=300)
20
 
21
  st.title("Explainable AI")
22
 
 
 
23
  df_unclean = pd.read_csv("ifood-data.csv")
24
  df = df_unclean.dropna()
25
  df = df[df["Year_Birth"] > 1940]
 
20
 
21
  st.title("Explainable AI")
22
 
23
+ st.write("For this example, a decision tree model with a max depth of 6 was used.")
24
+
25
  df_unclean = pd.read_csv("ifood-data.csv")
26
  df = df_unclean.dropna()
27
  df = df[df["Year_Birth"] > 1940]
pages/05 πŸ§‘β€πŸ’» Insights.py CHANGED
@@ -21,3 +21,40 @@ ideal_age = response_by_age.idxmax()
21
  highest_response_proportion = response_by_age.max()
22
 
23
  st.metric(value = ideal_age, label = "Ideal Birth Year")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  highest_response_proportion = response_by_age.max()
22
 
23
  st.metric(value = ideal_age, label = "Ideal Birth Year")
24
+
25
+ # Define the number of bins for recency segmentation
26
+ num_bins = 10
27
+
28
+ # Create bins for recency segmentation
29
+ df['Recency_bins'] = pd.cut(df['Recency'], bins=num_bins)
30
+
31
+ # Calculate the average response for each recency bin
32
+ average_response = df.groupby('Recency_bins')['Response'].mean()
33
+
34
+ # Find the recency range with the highest average response
35
+ most_responsive_range = average_response.idxmax()
36
+
37
+ # Find the average rececny within the most responsive range
38
+ most_responsive_recency_avg = df.loc[df['Recency_bins'] == most_responsive_range, 'Recency'].mean()
39
+
40
+ st.metric(value = str(round(most_responsive_recency_avg, 2)), label = "Days since last visit")
41
+
42
+ df['NumWebVisitsMonth_bins'] = pd.cut(df['NumWebVisitsMonth'], bins=num_bins)
43
+
44
+ average_response = df.groupby('NumWebVisitsMonth')['Response'].mean()
45
+
46
+ most_responsive_range = average_response.idxmax()
47
+
48
+ most_responsive_NumWebVisitsMonth_avg = df.loc[df['NumWebVisitsMonth'] == most_responsive_range, 'NumWebVisitsMonth'].mean()
49
+
50
+ st.metric(value = str(round(most_responsive_NumWebVisitsMonth_avg, 2)), label = "Web visits per month")
51
+
52
+ df['MntWines_bins'] = pd.cut(df['MntWines'], bins=num_bins)
53
+
54
+ average_response = df.groupby('MntWines')['Response'].mean()
55
+
56
+ most_responsive_range = average_response.idxmax()
57
+
58
+ most_responsive_MntWines_avg = df.loc[df['MntWines'] == most_responsive_range, 'MntWines'].mean()
59
+
60
+ st.metric(value = "$"+ str(round(most_responsive_MntWines_avg, 2)), label = "Amount spent on wine")