-
Notifications
You must be signed in to change notification settings - Fork 0
/
FD_WebApp.py
7595 lines (7089 loc) · 459 KB
/
FD_WebApp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import streamlit as st
import pandas as pd
import numpy as np
import pickle
def header():
col1, col2 = st.columns([3, 1])
with col1:
st.markdown("""<h3 style='color: orange;'>HADDOU Khalid</h3>""", unsafe_allow_html=True)
with col2:
st.markdown("<h3 style='color: green;'>GrassFields</h3>", unsafe_allow_html=True)
st.image('GF_logo/GRASSFIELDS_LogoBG.png', width=150)
# Create a function for the Test page
def Test():
def display_user_input_parameters_CC():
# Collects user input features into dataframe
st.sidebar.header('User Input Parameters')
st.sidebar.markdown("""
[Example of CC input file](https://www.kaggle.com/datasets/mlg-ulb/creditcardfraud)
""")
uploaded_file = st.sidebar.file_uploader("Upload your input CSV file for CC", type=["csv"])
if uploaded_file is not None:
df = pd.read_csv(uploaded_file)
else:
def user_input_features():
Time= st.sidebar.slider('Time', 0, 172792, 1 )
V1 = st.sidebar.slider('V 1', -56, 2, 1 )
V2 = st.sidebar.slider('V 2', -72, 22, 1 )
V3 = st.sidebar.slider('V 3', -48, 9, 1 )
V4 = st.sidebar.slider('V 4', -5, 16, 1 )
V5 = st.sidebar.slider('V 5', -113, 34, 1 )
V6 = st.sidebar.slider('V 6', -26, 73, 1 )
V7 = st.sidebar.slider('V 7', -43, 120, 1 )
V8 = st.sidebar.slider('V 8', -73, 20, 1 )
V9 = st.sidebar.slider('V 9', -13, 15, 1 )
V10 = st.sidebar.slider('V 10', -24, 23, 1 )
V11 = st.sidebar.slider('V 11', -4, 12, 1 )
V12 = st.sidebar.slider('V 12', -18, 7, 1 )
V13 = st.sidebar.slider('V 13', -5, 7, 1 )
V14 = st.sidebar.slider('V 14', -19, 10, 1 )
V15 = st.sidebar.slider('V 15', -4, 8, 1 )
V16 = st.sidebar.slider('V 16', -14, 17, 1 )
V17 = st.sidebar.slider('V 17', -25, 9, 1 )
V18 = st.sidebar.slider('V 18', -9, 5, 1 )
V19 = st.sidebar.slider('V 19', -7, 5, 1 )
V20 = st.sidebar.slider('V 20', -54, 39, 1 )
V21 = st.sidebar.slider('V 21', -34, 27, 1 )
V22 = st.sidebar.slider('V 22', -10, 10, 1 )
V23 = st.sidebar.slider('V 23', -44, 22, 1 )
V24 = st.sidebar.slider('V 24', -2, 4, 1 )
V25 = st.sidebar.slider('V 25', -10, 7, 1 )
V26 = st.sidebar.slider('V 26', -2, 3, 1 )
V27 = st.sidebar.slider('V 27', -22, 31, 1 )
V28 = st.sidebar.slider('V 28', -15, 33, 1 )
Amount = st.sidebar.slider('Amount', 0, 25691, 1 )
data = {'Time':Time, 'V1':V1, 'V2':V2, 'V3':V3, 'V4':V4, 'V5':V5, 'V6':V6, 'V7':V7, 'V8':V8, 'V9':V9,
'V10':V10, 'V11':V11, 'V12':V12, 'V13':V13, 'V14':V14, 'V15':V15, 'V16':V16, 'V17':V17, 'V18':V18, 'V19':V19,
'V20':V20, 'V21':V21, 'V22':V22, 'V23':V23, 'V24':V24, 'V25':V25, 'V26':V26, 'V27':V27, 'V28':V28, 'Amount': Amount
}
features = pd.DataFrame(data, index=[0])
return features
df = user_input_features()
return df,uploaded_file
# st.subheader('User Input parameters')
def display_user_input_parameters_CMIYC():
# Collects user input features into dataframe
st.sidebar.header('User Input Parameters')
st.sidebar.markdown("""
[Example of CMIYC input file](https://www.kaggle.com/competitions/catch-me-if-you-can-intruder-detection-through-webpage-session-tracking2/data)
""")
uploaded_file = st.sidebar.file_uploader("Upload your input CSV file for CMIYC", type=["csv"])
if uploaded_file is not None:
df = pd.read_csv(uploaded_file)
else:
def user_input_features():
session_id= st.sidebar.slider('session_id', 0, 253561, 10000 )
site1 = st.sidebar.slider('site1', 1, 41601, 20000 )
site10 = st.sidebar.slider('site10', 1, 5924, 3000 )
site2 = st.sidebar.slider('site2', 1, 41599, 30000 )
site3 = st.sidebar.slider('site3', 1, 41600, 20000 )
site4 = st.sidebar.slider('site4', 1, 41599, 30000 )
site5 = st.sidebar.slider('site5', 1, 41599, 30000 )
site6 = st.sidebar.slider('site6', 1, 41599, 30000 )
site7 = st.sidebar.slider('site7', 1, 41600, 20000 )
site8 = st.sidebar.slider('site8', 1, 41600, 20000 )
site9 = st.sidebar.slider('site9', 1, 41600, 20000 )
data = {'session_id':session_id,
'site1':site1, 'site10':site10, 'site2':site2, 'site3':site3, 'site4':site4, 'site5':site5,
'site6':site6, 'site7':site7, 'site8':site8, 'site9':site9 }
features = pd.DataFrame(data, index=[0])
return features
df = user_input_features()
return df,uploaded_file
# st.subheader('User Input parameters')
def display_user_input_parameters_IEEE():
# Collects user input features into dataframe
st.sidebar.header('User Input Parameters')
st.sidebar.markdown("""
[Example of IEEE input file](https://www.kaggle.com/competitions/ieee-fraud-detection/data)
""")
uploaded_file = st.sidebar.file_uploader("Upload your input CSV file for IEEE", type=["csv"])
if uploaded_file is not None:
df = pd.read_csv(uploaded_file)
else:
# st.sidebar.write("Please upload a CSV file.")
df = None
return df, uploaded_file
def display_user_input_parameters_LOAN():
# Collects user input features into dataframe
st.sidebar.header('User Input Parameters')
st.sidebar.markdown("""
[Example of LOAN input file](https://www.kaggle.com/avikpaul4u/vehicle-loan-default-prediction)
""")
uploaded_file = st.sidebar.file_uploader("Upload your input CSV file for LOAN", type=["csv"])
if uploaded_file is not None:
df = pd.read_csv(uploaded_file)
else:
def user_input_features():
unique_id = st.sidebar.slider('UNIQUEID', 417428 , 671084 , 126828)
disbursed_amount = st.sidebar.slider('DISBURSED_AMOUNT', 13320 , 987354 , 487017 )
asset_cost = st.sidebar.slider('ASSET_COST', 37000 , 1328954 , 645977 )
ltv = st.sidebar.slider('LTV', 13 , 95 , 40 )
branch_id = st.sidebar.slider('BRANCH_ID', 1 , 261 , 130 )
supplier_id = st.sidebar.slider('SUPPLIER_ID', 10524 , 24803 , 7139 )
manufacturer_id = st.sidebar.slider('MANUFACTURER_ID', 45 , 156 , 55 )
current_pincode_id = st.sidebar.slider('CURRENT_PINCODE_ID',1 , 7345 , 3672 )
date_of_birth = st.sidebar.slider('DATE_OF_BIRTH', 0 , 14416 , 7208 )
employment_type = st.sidebar.slider('EMPLOYMENT_TYPE', 0 , 1 , 0 )
disbursal_date = st.sidebar.slider('DISBURSAL_DATE', 0 , 83 , 41 )
state_id = st.sidebar.slider('STATE_ID', 1 , 22 , 10 )
employee_code_id = st.sidebar.slider('EMPLOYEE_CODE_ID', 1 , 3795 , 1897 )
mobile_no_avl_flag = st.sidebar.slider('MOBILENO_AVL_FLAG', 1 , 1 , 0 )
aadhar_flag = st.sidebar.slider('AADHAR_FLAG',0 , 1 , 0 )
pan_flag = st.sidebar.slider('PAN_FLAG', 0 , 1 , 0 )
voter_id_flag = st.sidebar.slider('VOTERID_FLAG', 0 , 1 , 0 )
driving_flag = st.sidebar.slider('DRIVING_FLAG', 0 , 1 , 0 )
passport_flag = st.sidebar.slider('PASSPORT_FLAG', 0 , 1 , 0 )
perform_cns_score = st.sidebar.slider('PERFORM_CNS_SCORE', 0 , 890 , 445 )
perform_cns_score_description = st.sidebar.slider('PERFORM_CNS_SCORE_DESCRIPTION', 0 , 19 , 9 )
pri_no_of_accts = st.sidebar.slider('PRI_NO_OF_ACCTS', 0 , 453 , 226 )
pri_active_accts = st.sidebar.slider('PRI_ACTIVE_ACCTS', 0 , 144 , 72 )
pri_overdue_accts = st.sidebar.slider('PRI_OVERDUE_ACCTS',0 , 25 , 12 )
pri_current_balance = st.sidebar.slider('PRI_CURRENT_BALANCE', -6678296 , 96524920 , 51601608 )
pri_sanctioned_amount = st.sidebar.slider('PRI_SANCTIONED_AMOUNT', 0 , 1000000000 , 500000000 )
pri_disbursed_amount = st.sidebar.slider('PRI_DISBURSED_AMOUNT', 0 , 1000000000 , 500000000 )
sec_no_of_accts = st.sidebar.slider('SEC_NO_OF_ACCTS', 0 , 52 , 26 )
sec_active_accts = st.sidebar.slider('SEC_ACTIVE_ACCTS', 0 , 36 , 18 )
sec_overdue_accts = st.sidebar.slider('SEC_OVERDUE_ACCTS',0 , 8 , 4 )
sec_current_balance = st.sidebar.slider('SEC_CURRENT_BALANCE', -574647 , 36032852 , 18303749 )
sec_sanctioned_amount = st.sidebar.slider('SEC_SANCTIONED_AMOUNT',0 , 30000000 , 15000000 )
sec_disbursed_amount = st.sidebar.slider('SEC_DISBURSED_AMOUNT',0 , 30000000 , 15000000 )
primary_instal_amt = st.sidebar.slider('PRIMARY_INSTAL_AMT',0 , 25642806 , 12821403 )
sec_instal_amt = st.sidebar.slider('SEC_INSTAL_AMT',0 , 4170901 , 2085450 )
new_accts_in_last_six_months = st.sidebar.slider('NEW_ACCTS_IN_LAST_SIX_MONTHS', 0 , 35 , 17)
delinquent_accts_in_last_six_months = st.sidebar.slider('DELINQUENT_ACCTS_IN_LAST_SIX_MONTHS', 0 , 20 , 10 )
average_acct_age = st.sidebar.slider('AVERAGE_ACCT_AGE',0 , 191 , 95 )
credit_history_length = st.sidebar.slider('CREDIT_HISTORY_LENGTH', 0 , 290 , 145 )
no_of_inquiries = st.sidebar.slider('NO_OF_INQUIRIES', 0 , 36 , 18 )
# Create a dictionary to store the values
data = {
'UNIQUEID': unique_id, 'DISBURSED_AMOUNT': disbursed_amount, 'ASSET_COST': asset_cost, 'LTV': ltv, 'BRANCH_ID': branch_id,
'SUPPLIER_ID': supplier_id, 'MANUFACTURER_ID': manufacturer_id, 'CURRENT_PINCODE_ID': current_pincode_id,
'DATE_OF_BIRTH': date_of_birth, 'EMPLOYMENT_TYPE': employment_type, 'DISBURSAL_DATE': disbursal_date, 'STATE_ID': state_id,
'EMPLOYEE_CODE_ID': employee_code_id, 'MOBILENO_AVL_FLAG': mobile_no_avl_flag, 'AADHAR_FLAG': aadhar_flag,
'PAN_FLAG': pan_flag, 'VOTERID_FLAG': voter_id_flag, 'DRIVING_FLAG': driving_flag, 'PASSPORT_FLAG': passport_flag,
'PERFORM_CNS_SCORE': perform_cns_score, 'PERFORM_CNS_SCORE_DESCRIPTION': perform_cns_score_description,
'PRI_NO_OF_ACCTS': pri_no_of_accts, 'PRI_ACTIVE_ACCTS': pri_active_accts, 'PRI_OVERDUE_ACCTS': pri_overdue_accts,
'PRI_CURRENT_BALANCE': pri_current_balance, 'PRI_SANCTIONED_AMOUNT': pri_sanctioned_amount,
'PRI_DISBURSED_AMOUNT': pri_disbursed_amount, 'SEC_NO_OF_ACCTS': sec_no_of_accts, 'SEC_ACTIVE_ACCTS': sec_active_accts,
'SEC_OVERDUE_ACCTS': sec_overdue_accts, 'SEC_CURRENT_BALANCE': sec_current_balance,
'SEC_SANCTIONED_AMOUNT': sec_sanctioned_amount, 'SEC_DISBURSED_AMOUNT': sec_disbursed_amount,
'PRIMARY_INSTAL_AMT': primary_instal_amt, 'SEC_INSTAL_AMT': sec_instal_amt,
'NEW_ACCTS_IN_LAST_SIX_MONTHS': new_accts_in_last_six_months,
'DELINQUENT_ACCTS_IN_LAST_SIX_MONTHS': delinquent_accts_in_last_six_months,
'AVERAGE_ACCT_AGE': average_acct_age, 'CREDIT_HISTORY_LENGTH': credit_history_length, 'NO_OF_INQUIRIES': no_of_inquiries
}
features = pd.DataFrame(data, index=[0])
return features
df = user_input_features()
return df,uploaded_file
def display_user_input_parameters_NSD():
# Collects user input features into dataframe
st.sidebar.header('User Input Parameters')
st.sidebar.markdown("""
[Example of NSD input file](https://github.com/amazon-science/fraud-dataset-benchmark#data-sources)
""")
uploaded_file = st.sidebar.file_uploader("Upload your input CSV file for NSD", type=["csv"])
if uploaded_file is not None:
df = pd.read_csv(uploaded_file)
else:
def user_input_features():
Index = st.sidebar.slider('Index', 0, 1296674, 500000 )
trans_date_trans_time = st.sidebar.slider('trans date trans time', 0, 1819550, 700000 )
cc_num = st.sidebar.slider('cc num', 0, 5000000000000000, 2500000000000000 )
merchant = st.sidebar.slider('merchant', 0, 692, 250 )
category = st.sidebar.slider('category', 0, 5000000000000000, 2500000000000000 )
amt = st.sidebar.slider('amt', 1, 692 , 300 )
first = st.sidebar.slider('first', 0, 354, 200 )
last = st.sidebar.slider('last', 0, 485, 300 )
gender = st.sidebar.slider('gender', 0, 1, 1 )
street = st.sidebar.slider('street', 0, 998, 500 )
city = st.sidebar.slider('city', 0, 905, 500 )
state = st.sidebar.slider('state', 0, 5, 3 )
zip = st.sidebar.slider('zip', 1257, 99921, 50000 )
lat = st.sidebar.slider('lat', 21, 67, 50 )
long = st.sidebar.slider('long', -166, -68, -100 )
city_pop = st.sidebar.slider('city pop', 23, 2906700, 2000000 )
job = st.sidebar.slider('job', 0, 496, 200 )
dob = st.sidebar.slider('dob', 0, 983, 500 )
trans_num = st.sidebar.slider('trans_num', 0, 1852393, 500000 )
unix_time = st.sidebar.slider('unix time', 1325376000, 1388534000, 1350000000 )
merch_lat = st.sidebar.slider('merch lat', 20, 70, 50 )
merch_long = st.sidebar.slider('merch long', -167, -67, -100 )
data = {
'Index':Index, 'trans_date_trans_time':trans_date_trans_time, 'cc_num':cc_num, 'merchant':merchant, 'category':category, 'amt':amt,
'first':first, 'last':last, 'gender':gender, 'street':street, 'city':city, 'state':state, 'zip':zip, 'lat':lat,
'long':long, 'city_pop':city_pop, 'job':job, 'dob':dob, 'trans_num':trans_num, 'unix_time':unix_time,
'merch_lat':merch_lat, 'merch_long':merch_long
}
features = pd.DataFrame(data, index=[0])
return features
df = user_input_features()
return df,uploaded_file
def display_user_input_parameters_PS17():
# Collects user input features into dataframe
st.sidebar.header('User Input Parameters')
st.sidebar.markdown("""
[Example of PS17 input file](https://www.kaggle.com/datasets/ealaxi/paysim1)
""")
uploaded_file = st.sidebar.file_uploader("Upload your input CSV file for PS17", type=["csv"])
if uploaded_file is not None:
df = pd.read_csv(uploaded_file)
else:
def user_input_features():
step = st.sidebar.slider('step', 1, 743, 500 )
type = st.sidebar.slider('type', 0, 4, 2 )
amount = st.sidebar.slider('amount', 0, 92445520, 20000000 )
nameOrig = st.sidebar.slider('nameOrig', 0, 6353306, 3000000 )
oldbalanceOrg = st.sidebar.slider('oldbalanceOrg', 0, 59585040, 30000000 )
newbalanceOrig = st.sidebar.slider('newbalanceOrig', 0, 59585040, 30000000 )
nameDest = st.sidebar.slider('nameDest', 0, 49585040, 25000000 )
oldbalanceDest = st.sidebar.slider('oldbalanceDest', 0, 356015900, 150000000 )
newbalanceDest = st.sidebar.slider('newbalanceDest', 0, 356179300, 150000000 )
isFlaggedFraud = st.sidebar.slider('isFlaggedFraud', 0, 1, 0 )
data = {
'step':step, 'type':type, 'amount':amount, 'nameOrig':nameOrig, 'oldbalanceOrg':oldbalanceOrg,
'newbalanceOrig':newbalanceOrig, 'nameDest':nameDest, 'oldbalanceDest':oldbalanceDest,
'newbalanceDest':newbalanceDest ,'isFlaggedFraud':isFlaggedFraud,
}
features = pd.DataFrame(data, index=[0])
return features
df = user_input_features()
return df,uploaded_file
# Define a function to apply the model and display the predictions
def apply_model_and_display(df,load_clf, method_name):
if df is not None:
load_clf = pickle.load(open(f'Models/{load_clf}', 'rb'))
prediction = load_clf.predict(df)
prediction_proba = load_clf.predict_proba(df)
col1, col2 = st.columns(2)
with col1:
st.markdown(f"<h3 style='color: green;'>Prediction - {method_name}</h3>", unsafe_allow_html=True)
Classes = np.array(['NonFraud (0)', 'Fraud (1)'])
st.write(Classes[prediction])
with col2:
st.markdown("<h3 style='color: Blue;'>Prediction Probability</h3>", unsafe_allow_html=True)
st.write(prediction_proba)
else:
st.write('Data is None. Please make sure to upload a valid CSV file.')
# Define function to choose dataset and call corresponding user input function
def choose_dataset():
dataset_choice = st.sidebar.radio("Select Dataset", ['Credit-Card Dataset', 'Alice Dataset', 'IEEE dataset',
'LOAN dataset', 'NSD dataset', 'PaySim17 dataset'])
if dataset_choice == 'Credit-Card Dataset':
df, uploaded_file = display_user_input_parameters_CC()
return df, uploaded_file, dataset_choice
elif dataset_choice == 'Alice Dataset':
df, uploaded_file = display_user_input_parameters_CMIYC()
return df, uploaded_file, dataset_choice
elif dataset_choice == 'IEEE dataset':
df, uploaded_file = display_user_input_parameters_IEEE()
return df, uploaded_file, dataset_choice
elif dataset_choice == 'LOAN dataset':
df, uploaded_file = display_user_input_parameters_LOAN()
return df, uploaded_file, dataset_choice
elif dataset_choice == 'NSD dataset':
df, uploaded_file = display_user_input_parameters_NSD()
return df, uploaded_file, dataset_choice
else:
df, uploaded_file = display_user_input_parameters_PS17()
return df, uploaded_file, dataset_choice
header()
# Create a function for the page
def LR():
df, uploaded_file, dataset_choice = choose_dataset()
st.write(f"""
# Simple Fraud Prediction App Using Imbalanced Data With {dataset_choice}
This app predicts the transaction type! (Fraud, NonFraud)
""")
if uploaded_file is not None:
st.write(df)
else:
st.write('Awaiting CSV file to be uploaded. Currently using example input parameters (shown in left sidebar).')
st.write(df)
# st.subheader('Logistic Regression Algorithms Results (Predictions) ')
st.markdown("<h3 style='color: Brown;'>Logistic Regression Algorithms Results (Predictions)</h3>", unsafe_allow_html=True)
# Apply the function for each method
if dataset_choice == 'Credit-Card Dataset':
methods_LR = [
('CC/CC_LogisticRegression_RUS.pkl', 'RUS'), ('CC/CC_LogisticRegression_ROS.pkl', 'ROS'),
('CC/CC_LogisticRegression_SMOTE.pkl', 'SMOTE'), ('CC/CC_LogisticRegression_SMOTEENN.pkl', 'SMOTEENN'),
('CC/CC_LogisticRegression_BSMOTE.pkl', 'BSMOTE'), ('CC/CC_LogisticRegression_ADASYN.pkl', 'ADASYN')
]
elif dataset_choice == 'Alice Dataset':
methods_LR = [
('CMIYC/CMIYC_LogisticRegression_RUS.pkl', 'RUS'), ('CMIYC/CMIYC_LogisticRegression_ROS.pkl', 'ROS'),
('CMIYC/CMIYC_LogisticRegression_SMOTE.pkl', 'SMOTE'), ('CMIYC/CMIYC_LogisticRegression_SMOTEENN.pkl', 'SMOTEENN'),
('CMIYC/CMIYC_LogisticRegression_BSMOTE.pkl', 'BSMOTE'), ('CMIYC/CMIYC_LogisticRegression_ADASYN.pkl', 'ADASYN')
]
elif dataset_choice == 'IEEE dataset':
methods_LR = [
('IEEE/IEEE_LogisticRegression_RUS.pkl', 'RUS'), ('IEEE/IEEE_LogisticRegression_ROS.pkl', 'ROS'),
('IEEE/IEEE_LogisticRegression_SMOTE.pkl', 'SMOTE'), ('IEEE/IEEE_LogisticRegression_SMOTEENN.pkl', 'SMOTEENN'),
('IEEE/IEEE_LogisticRegression_BSMOTE.pkl', 'BSMOTE'), ('IEEE/IEEE_LogisticRegression_ADASYN.pkl', 'ADASYN')
]
elif dataset_choice == 'LOAN dataset':
methods_LR = [
('LOAN/LOAN_LogisticRegression_RUS.pkl', 'RUS'), ('LOAN/LOAN_LogisticRegression_ROS.pkl', 'ROS'),
('LOAN/LOAN_LogisticRegression_SMOTE.pkl', 'SMOTE'), ('LOAN/LOAN_LogisticRegression_SMOTEENN.pkl', 'SMOTEENN'),
('LOAN/LOAN_LogisticRegression_BSMOTE.pkl', 'BSMOTE'), ('LOAN/LOAN_LogisticRegression_ADASYN.pkl', 'ADASYN')
]
elif dataset_choice == 'NSD dataset':
methods_LR = [
('NSD/NSD_LogisticRegression_RUS.pkl', 'RUS'), ('NSD/NSD_LogisticRegression_ROS.pkl', 'ROS'),
('NSD/NSD_LogisticRegression_SMOTE.pkl', 'SMOTE'), ('NSD/NSD_LogisticRegression_SMOTEENN.pkl', 'SMOTEENN'),
('NSD/NSD_LogisticRegression_BSMOTE.pkl', 'BSMOTE'), ('NSD/NSD_LogisticRegression_ADASYN.pkl', 'ADASYN')
]
else:
methods_LR = [
('PS17/PS17_LogisticRegression_RUS.pkl', 'RUS'), ('PS17/PS17_LogisticRegression_ROS.pkl', 'ROS'),
('PS17/PS17_LogisticRegression_SMOTE.pkl', 'SMOTE'), ('PS17/PS17_LogisticRegression_SMOTEENN.pkl', 'SMOTEENN'),
('PS17/PS17_LogisticRegression_BSMOTE.pkl', 'BSMOTE'), ('PS17/PS17_LogisticRegression_ADASYN.pkl', 'ADASYN')
]
for clf, method_name in methods_LR:
apply_model_and_display(df, clf, method_name)
# Create a function for the page
def DT():
# Collects user input features into dataframe
df, uploaded_file, dataset_choice = choose_dataset()
st.write(f"""
# Simple Fraud Prediction App Using Imbalanced Data With {dataset_choice}
This app predicts the transaction type! (Fraud, NonFraud)
""")
st.subheader('User Input parameters')
if uploaded_file is not None:
st.write(df)
else:
st.write('Awaiting CSV file to be uploaded. Currently using example input parameters (shown in left sidebar).')
st.write(df)
st.markdown("<h3 style='color: Brown;'>Decision Tree Classifier Algorithms Results (Predictions)</h3>", unsafe_allow_html=True)
# Apply the function for each method
if dataset_choice == 'Credit-Card Dataset':
methods_DT = [
('CC/CC_DecisionTreeClassifier_RUS.pkl', 'RUS'), ('CC/CC_DecisionTreeClassifier_ROS.pkl', 'ROS'),
('CC/CC_DecisionTreeClassifier_SMOTE.pkl', 'SMOTE'), ('CC/CC_DecisionTreeClassifier_SMOTEENN.pkl', 'SMOTEENN'),
('CC/CC_DecisionTreeClassifier_BSMOTE.pkl', 'BSMOTE'), ('CC/CC_DecisionTreeClassifier_ADASYN.pkl', 'ADASYN')
]
elif dataset_choice == 'Alice Dataset':
methods_DT = [
('CMIYC/CMIYC_DecisionTreeClassifier_RUS.pkl', 'RUS'), ('CMIYC/CMIYC_DecisionTreeClassifier_ROS.pkl', 'ROS'),
('CMIYC/CMIYC_DecisionTreeClassifier_SMOTE.pkl', 'SMOTE'), ('CMIYC/CMIYC_DecisionTreeClassifier_SMOTEENN.pkl', 'SMOTEENN'),
('CMIYC/CMIYC_DecisionTreeClassifier_BSMOTE.pkl', 'BSMOTE'), ('CMIYC/CMIYC_DecisionTreeClassifier_ADASYN.pkl', 'ADASYN')
]
elif dataset_choice == 'IEEE dataset':
methods_DT = [
('IEEE/IEEE_DecisionTreeClassifier_RUS.pkl', 'RUS'), ('IEEE/IEEE_DecisionTreeClassifier_ROS.pkl', 'ROS'),
('IEEE/IEEE_DecisionTreeClassifier_SMOTE.pkl', 'SMOTE'), ('IEEE/IEEE_DecisionTreeClassifier_SMOTEENN.pkl', 'SMOTEENN'),
('IEEE/IEEE_DecisionTreeClassifier_BSMOTE.pkl', 'BSMOTE'), ('IEEE/IEEE_DecisionTreeClassifier_ADASYN.pkl', 'ADASYN')
]
elif dataset_choice == 'LOAN dataset':
methods_DT = [
('LOAN/LOAN_DecisionTreeClassifier_RUS.pkl', 'RUS'), ('LOAN/LOAN_DecisionTreeClassifier_ROS.pkl', 'ROS'),
('LOAN/LOAN_DecisionTreeClassifier_SMOTE.pkl', 'SMOTE'), ('LOAN/LOAN_DecisionTreeClassifier_SMOTEENN.pkl', 'SMOTEENN'),
('LOAN/LOAN_DecisionTreeClassifier_BSMOTE.pkl', 'BSMOTE'), ('LOAN/LOAN_DecisionTreeClassifier_ADASYN.pkl', 'ADASYN')
]
elif dataset_choice == 'NSD dataset':
methods_DT = [
('NSD/NSD_DecisionTreeClassifier_RUS.pkl', 'RUS'), ('NSD/NSD_DecisionTreeClassifier_ROS.pkl', 'ROS'),
('NSD/NSD_DecisionTreeClassifier_SMOTE.pkl', 'SMOTE'), ('NSD/NSD_DecisionTreeClassifier_SMOTEENN.pkl', 'SMOTEENN'),
('NSD/NSD_DecisionTreeClassifier_BSMOTE.pkl', 'BSMOTE'), ('NSD/NSD_DecisionTreeClassifier_ADASYN.pkl', 'ADASYN')
]
else:
methods_DT = [
('PS17/PS17_DecisionTreeClassifier_RUS.pkl', 'RUS'), ('PS17/PS17_DecisionTreeClassifier_ROS.pkl', 'ROS'),
('PS17/PS17_DecisionTreeClassifier_SMOTE.pkl', 'SMOTE'), ('PS17/PS17_DecisionTreeClassifier_SMOTEENN.pkl', 'SMOTEENN'),
('PS17/PS17_DecisionTreeClassifier_BSMOTE.pkl', 'BSMOTE'), ('PS17/PS17_DecisionTreeClassifier_ADASYN.pkl', 'ADASYN')
]
for clf, method_name in methods_DT:
apply_model_and_display(df, clf, method_name)
# Create a function for the page
def RF():
# Collects user input features into dataframe
df, uploaded_file, dataset_choice = choose_dataset()
st.write(f"""
# Simple Fraud Prediction App Using Imbalanced Data With {dataset_choice}
This app predicts the transaction type! (Fraud, NonFraud)
""")
st.subheader('User Input parameters')
if uploaded_file is not None:
st.write(df)
else:
st.write('Awaiting CSV file to be uploaded. Currently using example input parameters (shown in left sidebar).')
st.write(df)
# st.subheader('Random Forest Classifier Algorithms Results (Predictions) ')
st.markdown("<h3 style='color: Brown;'>Random Forest Classifier Algorithms Results (Predictions)</h3>", unsafe_allow_html=True)
# Apply the function for each method
if dataset_choice == 'Credit-Card Dataset':
methods_RF = [
('CC/CC_RandomForestClassifier_RUS.pkl', 'RUS'), ('CC/CC_RandomForestClassifier_ROS.pkl', 'ROS'),
('CC/CC_RandomForestClassifier_SMOTE.pkl', 'SMOTE'), ('CC/CC_RandomForestClassifier_SMOTEENN.pkl', 'SMOTEENN'),
('CC/CC_RandomForestClassifier_BSMOTE.pkl', 'BSMOTE'), ('CC/CC_RandomForestClassifier_ADASYN.pkl', 'ADASYN')
]
# elif dataset_choice == 'Alice Dataset':
# methods_RF = [
# ('/CMIYC/CMIYC_RandomForestClassifier_RUS.pkl', 'RUS'), ('/CMIYC/CMIYC_RandomForestClassifier_ROS.pkl', 'ROS'),
# ('/CMIYC/CMIYC_RandomForestClassifier_SMOTE.pkl', 'SMOTE'), ('/CMIYC/CMIYC_RandomForestClassifier_SMOTEENN.pkl', 'SMOTEENN'),
# ('/CMIYC/CMIYC_RandomForestClassifier_BSMOTE.pkl', 'BSMOTE'), ('/CMIYC/CMIYC_RandomForestClassifier_ADASYN.pkl', 'ADASYN')
# ]
elif dataset_choice == 'IEEE dataset':
methods_RF = [
('IEEE/IEEE_RandomForestClassifier_RUS.pkl', 'RUS'), ('IEEE/IEEE_RandomForestClassifier_ROS.pkl', 'ROS'),
('IEEE/IEEE_RandomForestClassifier_SMOTE.pkl', 'SMOTE'), ('IEEE/IEEE_RandomForestClassifier_SMOTEENN.pkl', 'SMOTEENN'),
('IEEE/IEEE_RandomForestClassifier_BSMOTE.pkl', 'BSMOTE'), ('IEEE/IEEE_RandomForestClassifier_ADASYN.pkl', 'ADASYN')
]
# elif dataset_choice == 'LOAN dataset':
# methods_RF = [
# ('LOAN/LOAN_RandomForestClassifier_RUS.pkl', 'RUS'), ('LOAN/LOAN_RandomForestClassifier_ROS.pkl', 'ROS'),
# ('LOAN/LOAN_RandomForestClassifier_SMOTE.pkl', 'SMOTE'), ('LOAN/LOAN_RandomForestClassifier_SMOTEENN.pkl', 'SMOTEENN'),
# ('LOAN/LOAN_RandomForestClassifier_BSMOTE.pkl', 'BSMOTE'), ('LOAN/LOAN_RandomForestClassifier_ADASYN.pkl', 'ADASYN')
# ]
# elif dataset_choice == 'NSD dataset':
# methods_RF = [
# ('NSD/NSD_RandomForestClassifier_RUS.pkl', 'RUS'), ('NSD/NSD_RandomForestClassifier_ROS.pkl', 'ROS'),
# ('NSD/NSD_RandomForestClassifier_SMOTE.pkl', 'SMOTE'), ('NSD/NSD_RandomForestClassifier_SMOTEENN.pkl', 'SMOTEENN'),
# ('NSD/NSD_RandomForestClassifier_BSMOTE.pkl', 'BSMOTE'), ('NSD/NSD_RandomForestClassifier_ADASYN.pkl', 'ADASYN')
# ]
# else:
# methods_RF = [
# ('PS17/PS17_RandomForestClassifier_RUS.pkl', 'RUS'), ('PS17/PS17_RandomForestClassifier_ROS.pkl', 'ROS'),
# ('PS17/PS17_RandomForestClassifier_SMOTE.pkl', 'SMOTE'), ('PS17/PS17_RandomForestClassifier_SMOTEENN.pkl', 'SMOTEENN'),
# ('PS17/PS17_RandomForestClassifier_BSMOTE.pkl', 'BSMOTE'), ('PS17/PS17_RandomForestClassifier_ADASYN.pkl', 'ADASYN')
# ]
else:
methods_RF = []
st.write(f"""
# This algorithm is not yet deployed due to its large size which is not supported by the github repository.
You can choose to run locally the Web App saved on the hard disk or try the corrected version of this project available on the link mention on the repository Inbalanced dataset- fraud detection .Thanks
""")
for clf, method_name in methods_RF:
apply_model_and_display(df, clf, method_name)
# Create a function for the page
def XGB():
# Collects user input features into dataframe
df, uploaded_file, dataset_choice = choose_dataset()
st.write(f"""
# Simple Fraud Prediction App Using Imbalanced Data With {dataset_choice}
This app predicts the transaction type! (Fraud, NonFraud)
""")
if uploaded_file is not None:
st.write(df)
else:
st.write('Awaiting CSV file to be uploaded. Currently using example input parameters (shown in left sidebar).')
st.write(df)
# st.subheader('Random Forest Classifier Algorithms Results (Predictions) ')
st.markdown("<h3 style='color: Brown;'>XGBoost Classifier Algorithms Results (Predictions)</h3>", unsafe_allow_html=True)
# Apply the function for each method
if dataset_choice == 'Credit-Card Dataset':
methods_XGB = [
('CC/CC_XGBClassifier_RUS.pkl', 'RUS'), ('CC/CC_XGBClassifier_ROS.pkl', 'ROS'),
('CC/CC_XGBClassifier_SMOTE.pkl', 'SMOTE'), ('CC/CC_XGBClassifier_SMOTEENN.pkl', 'SMOTEENN'),
('CC/CC_XGBClassifier_BSMOTE.pkl', 'BSMOTE'), ('CC/CC_XGBClassifier_ADASYN.pkl', 'ADASYN')
]
elif dataset_choice == 'Alice Dataset':
methods_XGB = [
('CMIYC/CMIYC_XGBClassifier_RUS.pkl', 'RUS'), ('CMIYC/CMIYC_XGBClassifier_ROS.pkl', 'ROS'),
('CMIYC/CMIYC_XGBClassifier_SMOTE.pkl', 'SMOTE'), ('CMIYC/CMIYC_XGBClassifier_SMOTEENN.pkl', 'SMOTEENN'),
('CMIYC/CMIYC_XGBClassifier_BSMOTE.pkl', 'BSMOTE'), ('CMIYC/CMIYC_XGBClassifier_ADASYN.pkl', 'ADASYN')
]
elif dataset_choice == 'IEEE dataset':
methods_XGB = [
('IEEE/IEEE_XGBClassifier_RUS.pkl', 'RUS'), ('IEEE/IEEE_XGBClassifier_ROS.pkl', 'ROS'),
('IEEE/IEEE_XGBClassifier_SMOTE.pkl', 'SMOTE'), ('IEEE/IEEE_XGBClassifier_SMOTEENN.pkl', 'SMOTEENN'),
('IEEE/IEEE_XGBClassifier_BSMOTE.pkl', 'BSMOTE'), ('IEEE/IEEE_XGBClassifier_ADASYN.pkl', 'ADASYN')
]
elif dataset_choice == 'LOAN dataset':
methods_XGB = [
('LOAN/LOAN_XGBClassifier_RUS.pkl', 'RUS'), ('LOAN/LOAN_XGBClassifier_ROS.pkl', 'ROS'),
('LOAN/LOAN_XGBClassifier_SMOTE.pkl', 'SMOTE'), ('LOAN/LOAN_XGBClassifier_SMOTEENN.pkl', 'SMOTEENN'),
('LOAN/LOAN_XGBClassifier_BSMOTE.pkl', 'BSMOTE'), ('LOAN/LOAN_XGBClassifier_ADASYN.pkl', 'ADASYN')
]
elif dataset_choice == 'NSD dataset':
methods_XGB = [
('NSD/NSD_XGBClassifier_RUS.pkl', 'RUS'), ('NSD/NSD_XGBClassifier_ROS.pkl', 'ROS'),
('NSD/NSD_XGBClassifier_SMOTE.pkl', 'SMOTE'), ('NSD/NSD_XGBClassifier_SMOTEENN.pkl', 'SMOTEENN'),
('NSD/NSD_XGBClassifier_BSMOTE.pkl', 'BSMOTE'), ('NSD/NSD_XGBClassifier_ADASYN.pkl', 'ADASYN')
]
else:
methods_XGB = [
('PS17/PS17_XGBClassifier_RUS.pkl', 'RUS'), ('PS17/PS17_XGBClassifier_ROS.pkl', 'ROS'),
('PS17/PS17_XGBClassifier_SMOTE.pkl', 'SMOTE'), ('PS17/PS17_XGBClassifier_SMOTEENN.pkl', 'SMOTEENN'),
('PS17/PS17_XGBClassifier_BSMOTE.pkl', 'BSMOTE'), ('PS17/PS17_XGBClassifier_ADASYN.pkl', 'ADASYN')
]
for clf, method_name in methods_XGB:
apply_model_and_display(df, clf, method_name)
selected_function = st.sidebar.radio("Select Models", ['Logistic Regression', 'Decision Tree Classifier', 'Random Forest Classifier', 'XGBoost Classifier'])
if selected_function == 'Logistic Regression':
LR()
elif selected_function == 'Decision Tree Classifier':
DT()
elif selected_function == 'Random Forest Classifier':
RF()
elif selected_function == 'XGBoost Classifier':
XGB()
# Create a function for the Info page
def Info():
# Create a sidebar
# Display content for Option 1
with st.sidebar:
st.markdown("# Details about trained models")
# Add sidebar elements
sidebar_option = st.selectbox("Select a model", ["Methodology", "Dataset info", "LR", "DT","RF", "XGB"])
# Sidebar option dependent content
def Methodology():
header()
st.write("""
Here we present the details about models, evaluation metrics and methods used in the simulations.\n
In our simulations, we employed a variety of models, datasets, evaluation metrics, and methods to ensure a comprehensive analysis of the data. Our primary modeling algorithms were Logistic regression (LR), Decision Tree (DT), Random Forest (RF), XGBoost Classifier (XGB). a versatile ensemble learning technique known for its robustness and ability to handle both classification and regression tasks effectively.\n
To address potential class imbalance issues in our dataset, we employed several resampling techniques to create balanced training sets. These methods included:\n
- Random Undersampling (RUS): RUS involves reducing the size of the majority class by randomly removing instances. This helps prevent the model from being biased toward the dominant class.
- Random Oversampling (ROS): ROS, on the other hand, involves increasing the number of instances in the minority class by duplicating or generating synthetic samples. This helps ensure that the model does not ignore the minority class.
- SMOTE (Synthetic Minority Over-sampling Technique): SMOTE is a popular oversampling technique that generates synthetic examples for the minority class by interpolating between existing instances. This method helps address class imbalance while avoiding overfitting.\n
- SMOTEENN (SMOTE + Edited Nearest Neighbors): SMOTEENN a hybrid resampling technique that combines the Synthetic Minority Over-sampling Technique (SMOTE) with Edited Nearest Neighbors (ENN). It first applies SMOTE to oversample the minority class by generating synthetic samples, similar to SMOTE. However, it then employs ENN to remove noisy and potentially misclassified examples. This two-step process helps improve the balance of the classes while eliminating potential outliers, resulting in a more robust and balanced dataset.
- BorderlineSMOTE (BSMOTE): BSMOTE is an oversampling technique designed specifically for addressing imbalanced datasets. It focuses on the borderline instances of the minority class, which are samples that are closer to the majority class. BSMOTE generates synthetic examples for these borderline instances, helping to increase the representation of the minority class. This method is effective in improving classification performance for imbalanced datasets without oversaturating the dataset with synthetic samples.
- ADASYN (Adaptive Synthetic Sampling): ADASYN is an adaptive oversampling technique that aims to address class imbalance by generating synthetic samples for the minority class. Unlike fixed oversampling techniques, ADASYN assesses the density distribution of minority class instances. It assigns a higher priority to generating synthetic samples for minority instances that are more challenging to classify, effectively adapting to the local density of the data. This adaptability makes ADASYN suitable for scenarios where class imbalance varies across the dataset.
To account for potential disparities in the cost associated with different classes or prediction errors, we employed *cost-sensitive learning* techniques. These methods assign different weights to each class or type of misclassification error. This ensures that the model takes into consideration the specific costs involved in its predictions, leading to more realistic and actionable results in real-world scenarios.
To carry out these simulations, we used carefully selected datasets from different sources and covering a variety of domains, including real data, transformed data, simulated synthetic data and anonymised data. These datasets play a crucial role in the quality, accuracy and relevance of the results obtained.
For further elaboration on these datasets, please navigate to the left sidebar and select the desired dataset.
""")
st.write("""
By utilizing a combination of Logistic regression (LR), Decision Tree (DT), Random Forest (RF), and XGBoost Classifier (XGB) modeling, with resampling techniques (RUS, ROS, and SMOTE, SMOTEENN, BorderlineSMOTE(BSMOTE), ADASYN), and cost-sensitive learning methods, our simulations aimed to provide a robust and holistic assessment of the data, ensuring that our models were capable of handling class imbalances and optimizing their performance for practical applications.
""")
def Info_CC():
if sidebar_option == "Methodology":
Methodology()
elif sidebar_option == "Dataset info":
header()
st.write('## Credit-Card Dataset (CC)')
st.write("""
CC Dataset (anonymised)
The dataset contains credit card transactions made in September 2013 by European cardholders.
This dataset shows transactions that took place over two days, where we have 492 frauds out of 284315 transactions. The dataset is highly unbalanced, with the positive class (frauds) representing 0.1727% of all transactions.
It contains only numerical input variables which are the result of a PCA transformation. Unfortunately, for confidentiality reasons, it is not possible to provide the original characteristics and other information about the data.
The features `V1, V2, ... V28` are the principal components obtained with PCA. The only features that have not been transformed using PCA are `Time` and `Amount`.
- The `Time` characteristic contains the seconds elapsed between each transaction and the first transaction in the dataset.
- The `Amount` characteristic is the amount of the transaction. This feature can be used for cost-sensitive learning based on the example.
- The `Class` feature is the target variable and takes the value 1 in case of fraud and 0 otherwise.
The dataset was collected and analysed as part of a research collaboration between Worldline and the Machine Learning Group ([MLG ULB](http://mlg.ulb.ac.be)) of the ULB (Université Libre de Bruxelles) on massive data mining and fraud detection [[More Info]](https://mlg.ulb.ac.be/wordpress/portfolio_page/defeatfraud-assessment-and-validation-of-deep-feature-engineering-and-learning-solutions-for-fraud-detection/).
Link to dataset: [See here](https://www.kaggle.com/datasets/mlg-ulb/creditcardfraud) """)
elif sidebar_option == "LR":
# Display content for Option 1
header()
# Display text
st.markdown('<h3 style="color: green;">Evaluation Metrics Using LogisticRegression and different resampling methods:</h3>', unsafe_allow_html=True)
## RUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUS
st.markdown('<h3 style="color: brown;">RUS method: </h3>', unsafe_allow_html=True)
st.subheader("Evaluation Metrics")
# Create three columns
col1, col2 = st.columns(2)
# Table 1: Evaluation Metrics
with col1:
st.markdown("Performances Metrics")
st.markdown("""
| Metric | Score |
|----------------------------------|---------|
| Matthews Correlation Coefficient | 88.81 % |
| F1 Score | 94.61 % |
| Accuracy Score | 94.40 % |
| Recall Score | 95.18 % |
| Precision Score | 94.04 % |
| ROC AUC Score | 94.38 % |
| False Positive Rate | 06.41 % |
| Negative Predictive Value | 94.80 % |
""")
st.markdown("Confusion Matrix")
st.markdown("""
|Actual / Predicted| Negative | Positive |
|------------------|--------------------|--------------------|
| Negative | 73 | 5 |
| Positive | 4 | 79 |
""")
# Table 2: Confusion Matrix
with col2:
st.markdown("Classification Report")
st.markdown("""
| | Precision | Recall | F1_Score | Support |
|------------------|-----------|--------|----------|---------|
| 0 | 0.95 | 0.94 | 0.94 | 78 |
| 1 | 0.94 | 0.95 | 0.95 | 83 |
| | | | | |
| **Accuracy** | | | 0.94 | 161 |
| **Macro Avg** | 0.94 | 0.94 | 0.94 | 161 |
| **Weighted Avg** | 0.94 | 0.94 | 0.94 | 161 |
""")
# Display a local image
st.subheader("ROC-AUC & Learning curve")
image = st.image("Figs/CC/CC_LogisticRegression_RUS.jpg", caption="The roc-auc curve and the learning curve the LR algorithm by applying RUS resampling")#, use_container_width=True
# ROOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOS
st.markdown('<h3 style="color: brown;">ROS method: </h3>', unsafe_allow_html=True)
st.subheader("Evaluation Metrics")
# Create three columns
col1, col2 = st.columns(2)
# Table 1: Evaluation Metrics
with col1:
st.markdown("Performances Metrics")
st.markdown("""
| Metric | Score |
|----------------------------------|---------|
| Matthews Correlation Coefficient | 86.89 % |
| F1 Score | 93.12 % |
| Accuracy Score | 93.33 % |
| Recall Score | 89.85 % |
| Precision Score | 96.63 % |
| ROC AUC Score | 93.35 % |
| False Positive Rate | 03.14 % |
| Negative Predictive Value | 90.45 % |
""")
st.markdown("Confusion Matrix")
st.markdown("""
|Actual / Predicted| Negative | Positive |
|------------------|--------------------|--------------------|
| Negative | 48737 | 1585 |
| Positive | 5142 | 45537 |
""")
# Table 2: Confusion Matrix
with col2:
st.markdown("Classification Report")
st.markdown("""
| | Precision | Recall | F1_Score | Support |
|------------------|-----------|--------|----------|------------|
| 0 | 0.90 | 0.97 | 0.94 | 50322 |
| 1 | 0.97 | 0.90 | 0.93 | 50679 |
| | | | | |
| **Accuracy** | | | 0.93 | 101001 |
| **Macro Avg** | 0.94 | 0.93 | 0.93 | 101001 |
| **Weighted Avg** | 0.94 | 0.93 | 0.93 | 101001 |
""")
# Display a local image
st.subheader("ROC-AUC & Learning curve")
image = st.image("Figs/CC/CC_LogisticRegression_ROS.jpg", caption="The roc-auc curve and the learning curve the LR algorithm by applying ROS resampling")#, use_container_width=True
# SMOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOTE
st.markdown('<h3 style="color: brown;">SMOTE method: </h3>', unsafe_allow_html=True)
st.subheader("Evaluation Metrics")
# Create three columns
col1, col2 = st.columns(2)
# Table 1: Evaluation Metrics
with col1:
st.markdown("Performances Metrics")
st.markdown("""
| Metric | Score |
|----------------------------------|-------------------------|
| Matthews Correlation Coefficient | 95.17 % |
| F1 Score | 97.56 % |
| Accuracy Score | 97.57 % |
| Recall Score | 96.66 % |
| Precision Score | 98.47 % |
| ROC AUC Score | 97.58 % |
| False Positive Rate | 01.50 % |
| Negative Predictive Value | 96.70 % |
""")
st.markdown("Confusion Matrix")
st.markdown("""
|Actual / Predicted| Negative | Positive |
|------------------|--------------------|--------------------|
| Negative | 49565 | 757 |
| Positive | 1688 | 48991 |
""")
# Table 2: Confusion Matrix
with col2:
st.markdown("Classification Report")
st.markdown("""
| | Precision | Recall | F1_Score | Support |
|------------------|-----------|--------|----------|------------|
| 0 | 0.97 | 0.98 | 0.98 | 50322 |
| 1 | 0.98 | 0.97 | 0.98 | 50679 |
| | | | | |
| **Accuracy** | | | 0.98 | 101001 |
| **Macro Avg** | 0.98 | 0.98 | 0.98 | 101001 |
| **Weighted Avg** | 0.98 | 0.98 | 0.98 | 101001 |
""")
# Display a local image
st.subheader("ROC-AUC & Learning curve")
image = st.image("Figs/CC/CC_LogisticRegression_SMOTE.jpg", caption="The roc-auc curve and the learning curve the LR algorithm by applying SMOTE resampling")#, use_container_width=True
# SMOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOTEEEEEEEEEEEEENNNNNNNNNNNNNNNN
st.markdown('<h3 style="color: brown;">SMOTEENN method: </h3>', unsafe_allow_html=True)
st.subheader("Evaluation Metrics")
# Create three columns
col1, col2 = st.columns(2)
# Table 1: Evaluation Metrics
with col1:
st.markdown("Performances Metrics")
st.markdown("""
| Metric | Score |
|----------------------------------|-------------------------|
| Matthews Correlation Coefficient | 95.72 % |
| F1 Score | 97.88 % |
| Accuracy Score | 97.86 % |
| Recall Score | 97.52 % |
| Precision Score | 98.24 % |
| ROC AUC Score | 97.86 % |
| False Positive Rate | 01.79 % |
| Negative Predictive Value | 97.47 % |
""")
st.markdown("Confusion Matrix")
st.markdown("""
|Actual / Predicted| Negative | Positive |
|------------------|--------------------|--------------------|
| Negative | 46704 | 851 |
| Positive | 1210 | 47569 |
""")
# Table 2: Confusion Matrix
with col2:
st.markdown("Classification Report")
st.markdown("""
| | Precision | Recall | F1_Score | Support |
|------------------|-----------|--------|----------|------------|
| 0 | 0.97 | 0.98 | 0.98 | 47555 |
| 1 | 0.98 | 0.98 | 0.98 | 48779 |
| | | | | |
| **Accuracy** | | | 0.98 | 96334 |
| **Macro Avg** | 0.98 | 0.98 | 0.98 | 96334 |
| **Weighted Avg** | 0.98 | 0.98 | 0.98 | 96334 |
""")
# Display a local image
st.subheader("ROC-AUC & Learning curve")
image = st.image("Figs/CC/CC_LogisticRegression_SMOTEENN.jpg", caption="The roc-auc curve and the learning curve the LR algorithm by applying SMOTEENN resampling")#, use_container_width=True
## BBBBBBBBSMOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOTE
st.markdown('<h3 style="color: brown;">BSMOTE method: </h3>', unsafe_allow_html=True)
st.subheader("Evaluation Metrics")
# Create three columns
col1, col2 = st.columns(2)
# Table 1: Evaluation Metrics
with col1:
st.markdown("Performances Metrics")
st.markdown("""
| Metric | Score |
|----------------------------------|---------|
| Matthews Correlation Coefficient | 98.23 % |
| F1 Score | 99.12 % |
| Accuracy Score | 99.11 % |
| Recall Score | 99.20 % |
| Precision Score | 99.03 % |
| ROC AUC Score | 99.11 % |
| False Positive Rate | 00.01 % |
| Negative Predictive Value | 99.19 % |
""")
st.markdown("Confusion Matrix")
st.markdown("""
|Actual / Predicted| Negative | Positive |
|------------------|--------------------|--------------------|
| Negative | 49832 | 490 |
| Positive | 405 | 50274 |
""")
# Table 2: Confusion Matrix
with col2:
st.markdown("Classification Report")
st.markdown("""
| | Precision | Recall | F1_Score | Support |
|------------------|-----------|--------|----------|------------|
| 0 | 0.99 | 0.99 | 0.99 | 50322 |
| 1 | 0.99 | 0.99 | 0.99 | 50679 |
| | | | | |
| **Accuracy** | | | 0.99 | 101001 |
| **Macro Avg** | 0.99 | 0.99 | 0.99 | 101001 |
| **Weighted Avg** | 0.99 | 0.99 | 0.99 | 101001 |
""")
# Display a local image
st.subheader("ROC-AUC & Learning curve")
image = st.image("Figs/CC/CC_LogisticRegression_BSMOTE.jpg", caption="The roc-auc curve and the learning curve the LR algorithm by applying BSMOTE resampling")#, use_container_width=True
## AaaaaaaaaaaaaaaaaaaaaaaaaDAaaaaaaaaaaaaaaaaaaaaaSsssssssssYyyyyNnnnn
st.markdown('<h3 style="color: brown;">ADASYN method: </h3>', unsafe_allow_html=True)
st.subheader("Evaluation Metrics")
# Create three columns
col1, col2 = st.columns(2)
# Table 1: Evaluation Metrics
with col1:
st.markdown("Performances Metrics")
st.markdown("""
| Metric | Score |
|----------------------------------|---------|
| Matthews Correlation Coefficient | 94.80 % |
| F1 Score | 97.36 % |
| Accuracy Score | 97.39 % |
| Recall Score | 96.35 % |
| Precision Score | 98.39 % |
| ROC AUC Score | 97.39 % |
| False Positive Rate | 01.56 % |
| Negative Predictive Value | 96.43 % |
""")
st.markdown("Confusion Matrix")
st.markdown("""
|Actual / Predicted| Negative | Positive |
|------------------|--------------------|--------------------|
| Negative | 49781 | 794 |
| Positive | 1841 | 48577 |
""")
# Table 2: Confusion Matrix
with col2:
st.markdown("Classification Report")
st.markdown("""
| | Precision | Recall | F1_Score | Support |
|------------------|-----------|--------|----------|------------|
| 0 | 0.96 | 0.98 | 0.97 | 50575 |
| 1 | 0.98 | 0.96 | 0.97 | 50418 |
| | | | | |
| **Accuracy** | | | 0.97 | 100993 |
| **Macro Avg** | 0.97 | 0.97 | 0.97 | 100993 |
| **Weighted Avg** | 0.97 | 0.97 | 0.97 | 100993 |
""")
# Display a local image
st.subheader("ROC-AUC & Learning curve")
image = st.image("Figs/CC/CC_LogisticRegression_ADASYN.jpg", caption="The roc-auc curve and the learning curve the LR algorithm by applying ADASYN resampling")#, use_container_width=True
elif sidebar_option == "DT":
# Display content for Option 1
header()
# Display text
st.markdown('<h3 style="color: green;">Evaluation Metrics Using DecisionTreeClassifier and different resampling methods:</h3>', unsafe_allow_html=True)
## RUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUS
st.markdown('<h3 style="color: brown;">RUS method: </h3>', unsafe_allow_html=True)
st.subheader("Evaluation Metrics")
# Create three columns
col1, col2 = st.columns(2)
# Table 1: Evaluation Metrics
with col1:
st.markdown("Performances Metrics")
st.markdown("""
| Metric | Score |
|----------------------------------|---------|
| Matthews Correlation Coefficient | 82.78 % |
| F1 Score | 91.86 % |
| Accuracy Score | 91.30 % |
| Recall Score | 95.18 % |
| Precision Score | 88.76 % |
| ROC AUC Score | 91.18 % |
| False Positive Rate | 12.82 % |
| Negative Predictive Value | 94.44 % |
""")
st.markdown("Confusion Matrix")
st.markdown("""
|Actual / Predicted| Negative | Positive |
|------------------|--------------------|--------------------|
| Negative | 68 | 10 |
| Positive | 4 | 79 |
""")
# Table 2: Confusion Matrix
with col2:
st.markdown("Classification Report")
st.markdown("""
| | Precision | Recall | F1_Score | Support |
|------------------|-----------|--------|----------|---------|
| 0 | 0.94 | 0.87 | 0.91 | 78 |
| 1 | 0.89 | 0.95 | 0.92 | 83 |
| | | | | |
| **Accuracy** | | | 0.91 | 161 |
| **Macro Avg** | 0.92 | 0.91 | 0.91 | 161 |
| **Weighted Avg** | 0.92 | 0.91 | 0.91 | 161 |
""")
# Display a local image
st.subheader("ROC-AUC & Learning curve")
image = st.image("Figs/CC/CC_DecisionTreeClassifier_RUS.jpg", caption="The roc-auc curve and the learning curve the DT algorithm by applying RUS resampling")#, use_container_width=True
# ROOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOS
st.markdown('<h3 style="color: brown;">ROS method: </h3>', unsafe_allow_html=True)
st.subheader("Evaluation Metrics")
# Create three columns
col1, col2 = st.columns(2)
# Table 1: Evaluation Metrics
with col1:
st.markdown("Performances Metrics")
st.markdown("""
| Metric | Score |
|----------------------------------|---------|
| Matthews Correlation Coefficient | 99.97 % |
| F1 Score | 99.99 % |
| Accuracy Score | 99.99 % |
| Recall Score | 100.0 % |
| Precision Score | 99.97 % |
| ROC AUC Score | 99.99 % |