Spaces:
Runtime error
Runtime error
Commit
·
1340008
1
Parent(s):
1b3c491
tree structure
Browse files
app.py
CHANGED
@@ -15,11 +15,28 @@ def onehot(df, column):
|
|
15 |
def dataframe(file_obj):
|
16 |
df = pd.read_csv(file_obj.name)
|
17 |
df = onehot(df, column='type')
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
print(df.shape)
|
20 |
y_pred = model.predict(df)
|
21 |
|
22 |
-
pred_df = pd.DataFrame(y_pred, columns = ['
|
23 |
#append the predictions to the original dataframe
|
24 |
pred_df = pd.concat([df, pred_df], axis=1)
|
25 |
print(type(pred_df))
|
@@ -28,14 +45,15 @@ def dataframe(file_obj):
|
|
28 |
# return 'Classification Report:\n'+ clr
|
29 |
return pred_df
|
30 |
|
31 |
-
file = gr.
|
32 |
-
y_pred_df = gr.
|
|
|
33 |
interface_csv = gr.Interface(
|
34 |
fn=dataframe,
|
35 |
inputs=file,
|
36 |
outputs=y_pred_df,
|
37 |
title="Fraud Detection - EXPERT SYSTEM",
|
38 |
-
|
39 |
)
|
40 |
|
41 |
interface_csv.launch(inline=False)
|
|
|
15 |
def dataframe(file_obj):
|
16 |
df = pd.read_csv(file_obj.name)
|
17 |
df = onehot(df, column='type')
|
18 |
+
|
19 |
+
#if the 'type' column doesn't have value 'CASH_OUT' then add a column 'type_CASH_OUT' with value 0
|
20 |
+
if 'type_CASH_OUT' not in df.columns:
|
21 |
+
df['type_CASH_OUT'] = 0
|
22 |
+
#if the 'type' column doesn't have value 'TRANSFER' then add a column 'type_TRANSFER' with value 0
|
23 |
+
if 'type_TRANSFER' not in df.columns:
|
24 |
+
df['type_TRANSFER'] = 0
|
25 |
+
#if the 'type' column doesn't have value 'PAYMENT' then add a column 'type_PAYMENT' with value 0
|
26 |
+
if 'type_PAYMENT' not in df.columns:
|
27 |
+
df['type_PAYMENT'] = 0
|
28 |
+
#if the 'type' column doesn't have value 'DEBIT' then add a column 'type_DEBIT' with value 0
|
29 |
+
if 'type_DEBIT' not in df.columns:
|
30 |
+
df['type_DEBIT'] = 0
|
31 |
+
#if the 'type' column doesn't have value 'PAYMENT' then add a column 'type_PAYMENT' with value 0
|
32 |
+
if 'type_PAYMENT' not in df.columns:
|
33 |
+
df['type_PAYMENT'] = 0
|
34 |
+
|
35 |
+
df = df.drop(['nameOrig','nameDest','isFraud'], axis=1)
|
36 |
print(df.shape)
|
37 |
y_pred = model.predict(df)
|
38 |
|
39 |
+
pred_df = pd.DataFrame(y_pred, columns = ['predictedFraud'])
|
40 |
#append the predictions to the original dataframe
|
41 |
pred_df = pd.concat([df, pred_df], axis=1)
|
42 |
print(type(pred_df))
|
|
|
45 |
# return 'Classification Report:\n'+ clr
|
46 |
return pred_df
|
47 |
|
48 |
+
file = gr.components.File(file_count="single", type="file", label="Fisierul CSV cu tranzactii", optional=False)
|
49 |
+
y_pred_df = gr.components.Dataframe(max_rows=20, max_cols=5, overflow_row_behaviour="paginate", type="pandas", label="predictedFraud - Predictii bazate pe modelul de clasificare /n isFraud - Etichetele reale")
|
50 |
+
tree_structure = gr.Image("https://imgur.com/a/dTj0c7X", label="Structura arborelui de decizie")
|
51 |
interface_csv = gr.Interface(
|
52 |
fn=dataframe,
|
53 |
inputs=file,
|
54 |
outputs=y_pred_df,
|
55 |
title="Fraud Detection - EXPERT SYSTEM",
|
56 |
+
description="Sistem expert bazat pe un model de clasificare pentru detectarea fraudelor in tranzactii bancare",
|
57 |
)
|
58 |
|
59 |
interface_csv.launch(inline=False)
|