Spaces:
Runtime error
Runtime error
Commit
·
61c1e74
1
Parent(s):
336ac28
added classification report
Browse files- app.py +39 -17
- report_nn.csv +6 -0
- report_tree.csv +6 -0
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import pickle
|
|
|
4 |
from tensorflow import keras
|
5 |
|
6 |
treemodel = pickle.load(open('decision_tree.pkl', 'rb'))
|
@@ -50,30 +51,51 @@ def nn(file_obj):
|
|
50 |
nn_df = pd.read_csv(file_obj.name)
|
51 |
nn_df = dataframe(nn_df)
|
52 |
y_prednn = nnmodel.predict(nn_df)
|
53 |
-
|
|
|
|
|
54 |
#append the predictions to the original dataframe
|
55 |
df_originalnn = pd.read_csv(file_obj.name)
|
56 |
-
pred_dfnn = pd.concat([df_originalnn, pred_dfnn], axis=1)
|
57 |
return pred_dfnn
|
58 |
|
59 |
file = gr.components.File(file_count="single", type="file", label="Fisierul CSV cu tranzactii", optional=False)
|
60 |
-
tree_output = gr.components.Dataframe(max_rows=20, max_cols=None, overflow_row_behaviour="paginate", type="pandas", label="predictedFraud - Predictii bazate pe modelul de clasificare
|
61 |
-
nn_output = gr.components.Dataframe(max_rows=20, max_cols=None, overflow_row_behaviour="paginate", type="pandas", label="predictedFraud - Predictii bazate pe modelul de clasificare
|
62 |
tree_interface = gr.Interface(
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
description='<h2>Sistem expert bazat pe un model de clasificare pentru detectarea fraudelor in tranzactii bancare.<h2><h3>predictedFraud - Predictii bazate pe modelul de clasificare. isFraud - Etichetele reale<h3>'
|
68 |
-
)
|
69 |
|
70 |
nn_interface = gr.Interface(
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
-
)
|
78 |
#tree_interface.launch(inline=True)
|
79 |
-
gr.Parallel(tree_interface, nn_interface).launch()
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import pickle
|
4 |
+
import numpy as np
|
5 |
from tensorflow import keras
|
6 |
|
7 |
treemodel = pickle.load(open('decision_tree.pkl', 'rb'))
|
|
|
51 |
nn_df = pd.read_csv(file_obj.name)
|
52 |
nn_df = dataframe(nn_df)
|
53 |
y_prednn = nnmodel.predict(nn_df)
|
54 |
+
pred_proc = pd.DataFrame(y_prednn, columns = ['predictedFraudProbability'])
|
55 |
+
pred=np.where(y_prednn<0.44,0,1)
|
56 |
+
pred_dfnn = pd.DataFrame(pred, columns = ['predictedFraud'])
|
57 |
#append the predictions to the original dataframe
|
58 |
df_originalnn = pd.read_csv(file_obj.name)
|
59 |
+
pred_dfnn = pd.concat([df_originalnn, pred_proc, pred_dfnn], axis=1)
|
60 |
return pred_dfnn
|
61 |
|
62 |
file = gr.components.File(file_count="single", type="file", label="Fisierul CSV cu tranzactii", optional=False)
|
63 |
+
tree_output = gr.components.Dataframe(max_rows=20, max_cols=None, overflow_row_behaviour="paginate", type="pandas", label="predictedFraud - Predictii bazate pe modelul de clasificare DECISION TREE")
|
64 |
+
nn_output = gr.components.Dataframe(max_rows=20, max_cols=None, overflow_row_behaviour="paginate", type="pandas", label="predictedFraud - Predictii bazate pe modelul de clasificare NEURAL NETWORK")
|
65 |
tree_interface = gr.Interface(
|
66 |
+
fn=tree,
|
67 |
+
inputs=file,
|
68 |
+
outputs=tree_output,
|
69 |
+
)
|
|
|
|
|
70 |
|
71 |
nn_interface = gr.Interface(
|
72 |
+
fn=nn,
|
73 |
+
inputs=file,
|
74 |
+
outputs=nn_output,
|
75 |
+
)
|
76 |
+
|
77 |
+
def report_tree():
|
78 |
+
creport_tree = pd.read_csv('report_tree.csv')
|
79 |
+
return creport_tree
|
80 |
+
|
81 |
+
def report_nn():
|
82 |
+
creport_nn = pd.read_csv('report_nn.csv')
|
83 |
+
return creport_nn
|
84 |
+
|
85 |
+
cr_tree = gr.components.DataFrame(type="pandas", label="Classification Report (Decision Tree)")
|
86 |
+
cr_nn = gr.components.DataFrame(type="pandas", label="Classification Report (Neural Network)")
|
87 |
+
|
88 |
+
r_tree = gr.Interface(
|
89 |
+
fn=report_tree,
|
90 |
+
inputs = None,
|
91 |
+
outputs = cr_tree,
|
92 |
+
)
|
93 |
+
|
94 |
+
r_nn = gr.Interface(
|
95 |
+
fn=report_nn,
|
96 |
+
inputs = None,
|
97 |
+
outputs = cr_nn,
|
98 |
+
)
|
99 |
|
|
|
100 |
#tree_interface.launch(inline=True)
|
101 |
+
gr.Parallel(tree_interface, nn_interface, r_tree, r_nn).launch()
|
report_nn.csv
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
metric,precision,recall,f1-score,support
|
2 |
+
not_fraud,1.00,1.00,1.00,1906322
|
3 |
+
fraud,0.64,0.86,0.73,2464
|
4 |
+
accuracy,,,1.00,1908786
|
5 |
+
macro avg,0.82,0.93,0.87,1908786
|
6 |
+
weighted avg,1.00,1.00,1.00,1908786
|
report_tree.csv
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
metric,precision,recall,f1-score,support
|
2 |
+
not_fraud,1.00,1.00,1.00,1906322
|
3 |
+
fraud,0.65,0.89,0.75,2464
|
4 |
+
accuracy,,,1.00,1908786
|
5 |
+
macro avg,0.83,0.95,0.88,1908786
|
6 |
+
weighted avg,1.00,1.00,1.00,1908786
|