Pranav216 commited on
Commit
ec0a796
·
1 Parent(s): cd7f163

Gradio Frontend

Browse files
__pycache__/main.cpython-312.pyc ADDED
Binary file (5.92 kB). View file
 
frontend.py CHANGED
@@ -1,2 +1,107 @@
1
  import gradio as gr
2
- from main import
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import main
3
+ import numpy as np
4
+ import pandas as pd
5
+ from main import clf_rf, clf_log, accuracy_score_rf, accuracy_score_lr, breier_score_rf, breier_score_lr, roc_rf, roc_lr
6
+
7
+ def eda(Graphs):
8
+ match Graphs:
9
+ case "Customer Churn":
10
+ return gr.Image("graphs/EDAGraphs/Churn.png")
11
+ case "Contract":
12
+ return gr.Image("graphs/EDAGraphs/Contract.png")
13
+ case "Dependents":
14
+ return gr.Image("graphs/EDAGraphs/Dependents.png")
15
+ case "Device Protection":
16
+ return gr.Image("graphs/EDAGraphs/DeviceProtection.png")
17
+ case "Heatmap":
18
+ return gr.Image("graphs/EDAGraphs/Heatmap.png")
19
+ case "Monthly Charges":
20
+ return gr.Image("graphs/EDAGraphs/MonthlyCharges.png")
21
+ case "Online Backup":
22
+ return gr.Image("graphs/EDAGraphs/OnlineBackup.png")
23
+ case "Online Security":
24
+ return gr.Image("graphs/EDAGraphs/OnlineSecurity.png")
25
+ case "Paperless Billing":
26
+ return gr.Image("graphs/EDAGraphs/PaperlessBilling.png")
27
+ case "Partner":
28
+ return gr.Image("graphs/EDAGraphs/Partner.png")
29
+ case "Payment Method":
30
+ return gr.Image("graphs/EDAGraphs/PaymentMethod.png")
31
+ case "Senior Citizen":
32
+ return gr.Image("graphs/EDAGraphs/SeniorCitizen.png")
33
+ case "Tech Support":
34
+ return gr.Image("graphs/EDAGraphs/TechSupport.png")
35
+ case "Tenure":
36
+ return gr.Image("graphs/EDAGraphs/tenure.png")
37
+
38
+ def result(Graphs):
39
+ match Graphs:
40
+ case "Correlation":
41
+ inf = "Enter inference here"
42
+ return [gr.Image("graphs/EDAGraphs/Correlation.png"), inf]
43
+ case "Confusion Matrix for Random Forest":
44
+ inf = "Enter inference here"
45
+ return [gr.Image("graphs/OutputGraphs/ConfusionMatrixRandomForest.png"), inf]
46
+ case "Confusion Matrix for Logistic regression":
47
+ inf = "Enter inference here"
48
+ return [gr.Image("graphs/OutputGraphs/ConfusionMatrixLogistic.png"), inf]
49
+ case "SHAP analysis for Random Forest":
50
+ inf = "Enter inference here"
51
+ return [gr.Image("graphs/OutputGraphs/SHAP_RandomForest_Summary.png"), inf]
52
+ case "SHAP analysis for Logistic Regression":
53
+ inf = "Enter inference here"
54
+ return [gr.Image("graphs/OutputGraphs/SHAP_Logistic_Summary.png"), inf]
55
+
56
+ def metrics(Algorithms):
57
+ match Algorithms:
58
+ case "Random Forest":
59
+ df = pd.DataFrame(clf_rf)
60
+ df = df.drop(columns = ['accuracy', 'macro avg', 'weighted avg']).T
61
+ df = df.reset_index().rename(columns={'index': 'class'})
62
+ df_clf = gr.DataFrame(
63
+ value = df
64
+ )
65
+ df_acc = gr.DataFrame(
66
+ headers = ['Accuracy Score', 'Breier Score', 'ROC Score'],
67
+ value = [list([accuracy_score_rf, breier_score_rf, roc_rf])],
68
+ )
69
+ return df_clf, df_acc
70
+
71
+ case "Logistic Regression":
72
+ df = pd.DataFrame(clf_log)
73
+ df = df.drop(columns = ['accuracy', 'macro avg', 'weighted avg']).T
74
+ df = df.reset_index().rename(columns={'index': 'class'})
75
+ df_clf = gr.DataFrame(
76
+ value = df
77
+ )
78
+ df_acc = gr.DataFrame(
79
+ headers = ['Accuracy Score', 'Breier Score', 'ROC Score'],
80
+ value = [list([accuracy_score_lr, breier_score_lr, roc_lr])],
81
+ )
82
+ return df_clf, df_acc
83
+
84
+ with gr.Blocks() as Output:
85
+ gr.Markdown("View Exploratory data Analysis and Output")
86
+ with gr.Tab("EDA Graphs"):
87
+ eda_input = gr.Radio(["Customer Churn", "Contract", "Dependents", "Device Protection", "Heatmap", "Monthly Charges", "Online Backup", "Online Security", "Paperless Billing", "Partner", "Payment Method", "Senior Citizen", "Tech Support", "Tenure"], show_label= False)
88
+ eda_output = gr.Image()
89
+
90
+ eda_input.change(fn = eda, inputs= eda_input, outputs= eda_output)
91
+
92
+ with gr.Tab("Output Graphs"):
93
+ result_input = gr.Radio(["Correlation", "Confusion Matrix for Random Forest", "Confusion Matrix for Logistic regression", "SHAP analysis for Random Forest", "SHAP analysis for Logistic Regression"], show_label = False)
94
+
95
+ result_output = [gr.Image(), gr.Label()]
96
+
97
+ result_input.change(fn = result, inputs=result_input, outputs = result_output)
98
+
99
+ with gr.Tab("Performance Metrics"):
100
+ algorithm = gr.Radio(["Random Forest", "Logistic Regression"], show_label= False)
101
+
102
+ metrics_output = [gr.DataFrame(), gr.DataFrame()]
103
+
104
+ algorithm.change(fn = metrics, inputs = algorithm, outputs = metrics_output)
105
+
106
+
107
+ Output.launch()
graphs/OutputGraphs/ConfusionMatrixRandomForest.png CHANGED
graphs/OutputGraphs/SHAP_RandomForest_Summary.png CHANGED
main.py CHANGED
@@ -62,6 +62,7 @@ y_rf_pred = rf_clf.predict(X_test)
62
  # Evaluating Random Forest
63
  print("\n\t\t\tRandom Forest Classifier:\n")
64
  print("Classification Report for Random Forest:")
 
65
  print(classification_report(y_test, y_rf_pred))
66
 
67
  cm = confusion_matrix(y_test, y_rf_pred)
@@ -70,12 +71,16 @@ display = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=rf_clf.clas
70
  display.plot(cmap=plt.cm.Blues)
71
  plt.savefig("graphs/OutputGraphs/ConfusionMatrixRandomForest.png")
72
 
 
 
 
 
73
  print("Brier Score Loss:")
74
- print(brier_score_loss(y_test, y_rf_pred))
75
  print("Accuracy Score:")
76
- print(accuracy_score(y_test, y_rf_pred))
77
  print("ROC AUC Score:")
78
- print(roc_auc_score(y_test, y_rf_pred))
79
 
80
 
81
  explainer = shap.TreeExplainer(rf_clf)
@@ -94,6 +99,7 @@ y_log_pred = logistic.predict(X_test)
94
  # Evaluating logistic
95
  print("\t\t\tLogistic Regression:\n")
96
  print("Classification Report for Logistic Regression:")
 
97
  print(classification_report(y_test, y_log_pred))
98
 
99
  cm = confusion_matrix(y_test, y_log_pred)
@@ -102,12 +108,16 @@ display = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=logistic.cl
102
  display.plot(cmap=plt.cm.Blues)
103
  plt.savefig("graphs/OutputGraphs/ConfusionMatrixLogistic.png")
104
 
 
 
 
 
105
  print("Brier Score Loss:")
106
- print(brier_score_loss(y_test, y_log_pred))
107
  print("Accuracy Score:")
108
- print(accuracy_score(y_test, y_log_pred))
109
  print("ROC AUC Score:")
110
- print(roc_auc_score(y_test, y_log_pred))
111
 
112
  # SHAP Analysis for logistic regression
113
  explainer = shap.LinearExplainer(logistic, X_train)
 
62
  # Evaluating Random Forest
63
  print("\n\t\t\tRandom Forest Classifier:\n")
64
  print("Classification Report for Random Forest:")
65
+ clf_rf = classification_report(y_test, y_rf_pred, output_dict= True)
66
  print(classification_report(y_test, y_rf_pred))
67
 
68
  cm = confusion_matrix(y_test, y_rf_pred)
 
71
  display.plot(cmap=plt.cm.Blues)
72
  plt.savefig("graphs/OutputGraphs/ConfusionMatrixRandomForest.png")
73
 
74
+ breier_score_rf = brier_score_loss(y_test, y_rf_pred)
75
+ accuracy_score_rf = accuracy_score(y_test, y_rf_pred)
76
+ roc_rf = roc_auc_score(y_test, y_rf_pred)
77
+
78
  print("Brier Score Loss:")
79
+ print(breier_score_rf)
80
  print("Accuracy Score:")
81
+ print(accuracy_score_rf)
82
  print("ROC AUC Score:")
83
+ print(roc_rf)
84
 
85
 
86
  explainer = shap.TreeExplainer(rf_clf)
 
99
  # Evaluating logistic
100
  print("\t\t\tLogistic Regression:\n")
101
  print("Classification Report for Logistic Regression:")
102
+ clf_log = classification_report(y_test, y_log_pred, output_dict= True)
103
  print(classification_report(y_test, y_log_pred))
104
 
105
  cm = confusion_matrix(y_test, y_log_pred)
 
108
  display.plot(cmap=plt.cm.Blues)
109
  plt.savefig("graphs/OutputGraphs/ConfusionMatrixLogistic.png")
110
 
111
+ breier_score_lr = brier_score_loss(y_test, y_log_pred)
112
+ accuracy_score_lr = accuracy_score(y_test, y_log_pred)
113
+ roc_lr = roc_auc_score(y_test, y_log_pred)
114
+
115
  print("Brier Score Loss:")
116
+ print(breier_score_lr)
117
  print("Accuracy Score:")
118
+ print(accuracy_score_lr)
119
  print("ROC AUC Score:")
120
+ print(roc_lr)
121
 
122
  # SHAP Analysis for logistic regression
123
  explainer = shap.LinearExplainer(logistic, X_train)